A - 高数Umaru系列(9)——哈士奇
#include <bits/stdc++.h>
using namespace std;
int n, mon;
int p[10000], m[10000];
signed main()
{
while (cin >> n >> mon)
{
int f[10000] = {0};
for (int i = 1; i <= n; i++)
cin >> p[i] >> m[i];
for (int i = 1; i <= n; i++)
for (int j = mon; j >= p[i]; j--)
f[j] = max(f[j], f[j - p[i]] + m[i]);
int ans = 0;
for (int i = 1; i <= mon; i++)
ans = max(ans, f[i]);
cout << ans << endl;
}
}
E - 石子合并问题
#include <bits/stdc++.h>
using namespace std;
int n, mon;
int p[10000], m[10000];
signed main()
{
while (cin >> n >> mon)
{
int f[10000] = {0};
for (int i = 1; i <= n; i++)
cin >> p[i] >> m[i];
for (int i = 1; i <= n; i++)
for (int j = mon; j >= p[i]; j--)
f[j] = max(f[j], f[j - p[i]] + m[i]);
int ans = 0;
for (int i = 1; i <= mon; i++)
ans = max(ans, f[i]);
cout << ans << endl;
}
}
标签:10000,int,namespace,第二个,mon,ans,main
From: https://www.cnblogs.com/zzh1206/p/16820752.html