这道题的数据真的太水了
本蒟蒻一开始想着敲个多重背包板子,确实是30分
但加了O2优化和快读就能直接90分
再把语言选择成编译器版本更新的C++11,竟然AC了?
代码如下:
#include <bits/stdc++.h>
#define putb putchar(' ')
#define putn putchar('\n')
using namespace std;
int n, m, w[110], v[110], c[110];
int dp[100010];
template <typename _Ip>
inline void read(_Ip &x) {
char ch = getchar(), sgn = 0; x = 0;
while (ch ^ '-' && !isdigit(ch)) ch = getchar();
if (ch == '-') ch = getchar(), sgn = 1;
while (isdigit(ch)) x = (x<<3)+(x<<1) + (ch^48), ch = getchar();
if (sgn) x = -x;
}
template <typename _Op>
inline void write(_Op x) {
if (x < 0) putchar('-'), x = -x;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
int main() {
read(n);read(m);
for (int i = 1; i <= n; ++i) {
read(v[i]);read(w[i]);read(c[i]);
}
for (int i = 1; i <= n; ++i) {
for (int j = m; j >= w[i]; --j) {
for (int k = 1; k <= c[i] && w[i]*k <= j; ++k) {
dp[j] = max(dp[j], dp[j-k*w[i]]+k*v[i]);
}
}
}
write(dp[m]);
return 0;
}
请求加强数据!