# 情人节限定dp打卡1

2023-02-14 18:53:01

1.

``````#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
#define x first
#define y second
#define ms(a,s) memset(a, s, sizeof a);
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
const int mod = 1e6+7;
const int inf = 0x3f3f3f3f;
const int N = 1010;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int a[N][N], f[N];
void solve() {
int n;
cin >> n;
for(int i = 1; i < n; i ++ ) {
for(int j = i + 1; j <= n; j ++ ) {
cin >> a[i][j];
}
f[i] = 1e7;
}
for(int i = n - 1; i >= 1; i -- ) {
for(int j = i + 1; j <= n; j ++ ) {
f[i] = min(f[i], f[j] + a[i][j]);
}
}
cout << f[1];
}
int main()
{
int t = 1;

//	cin >> t;

while(t --) {
solve();
}

return 0;
}
``````

2.

``````#include<bits/stdc++.h>
using namespace std;
int w[30],v[30],f[100010];
int n,m;
int main()
{
cin >> n >> m;
for(int i = 1; i <= m; i ++ )
{
cin >> v[i] >> w[i];
w[i] *= v[i];
}

for(int i = 1; i <= m; i ++ )
{
for(int j = n; j >= v[i]; j -- )
{
if(j >= v[i])
{
f[j]=max(f[j], f[j-v[i]] + w[i]);
}
}
}
cout<<f[n];
return 0;
} ``````

3.

``````#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
#define x first
#define y second
#define ms(a,s) memset(a, s, sizeof a);
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
const int mod = 1e6+7;
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 10;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
ll a[N], w[N], v[N], f[N];
void solve() {
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i ++ ) {
cin >> a[i] >> w[i] >> v[i];
}
for(int i = 1; i <= n; i ++ ) {
for(int j = m; j >= v[i]; j -- ) {
f[j] = max(f[j] + a[i], f[j - v[i]] + w[i]);
}
for(int j = v[i] - 1; j >= 0; j -- ) {
f[j] += a[i];
}
}
cout << f[m] * 5;
}
int main()
{
int t = 1;

//	cin >> t;

while(t --) {
solve();
}

return 0;
}
``````

...全文
13 回复 打赏 收藏 举报

4.2w+

2023-02-14 18:53

刷题！