P1164 小A点菜
本题链接:P1164 小A点菜
本博客给出本题截图:
#include <iostream> #include <algorithm> #include <cstring> using namespace std; const int N = 10010; int f[N]; int main() { int n, m; cin >> n >> m; f[0] = 1; for (int i = 1; i <= n; i ++ ) { int v; cin >> v; for (int j = m; j >= v; j -- ) f[j] += f[j - v]; } cout << f[m] << endl; return 0; }
P1510 精卫填海
本题链接:P1510 精卫填海
本博客给出本题截图:
#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 10010; int v[N], w[N]; int f[N]; int main() { int m, n, c; cin >> m >> n >> c; for (int i = 1; i <= n; i ++ ) cin >> w[i] >> v[i]; for (int i = 1; i <= n; i ++ ) for (int j = c; j >= v[i]; j -- ) f[j] = max(f[j], f[j - v[i]] + w[i]); if (f[c] < m) cout << "Impossible" << endl; else for (int i = 0; i <= c; i ++ ) if (f[i] >= m) { cout << c - i << endl; break; } return 0; }
P2639 [USACO09OCT]Bessie’s Weight Problem G
本题链接:P2639 [USACO09OCT]Bessie’s Weight Problem G
本博客给出本题截图:
#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 45010; int f[N]; int main() { int m, n; cin >> m >> n; for (int i = 1; i <= n; i ++ ) { int v; cin >> v; for (int j = m; j >= v; j -- ) f[j] = max(f[j], f[j - v] + v); } cout << f[m] << endl; return 0; }
P2925 [USACO08DEC]Hay For Sale S
本题链接:P2925 [USACO08DEC]Hay For Sale S
本博客给出本题截图:
#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 50010; int f[N]; int main() { int m, n; cin >> m >> n; for (int i = 1; i <= n; i ++ ) { int v; cin >> v; for (int j = m; j >= v; j -- ) f[j] = max(f[j], f[j - v] + v); } cout << f[m] << endl; return 0; }