Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
O(10*100000)的方法是不是巨弱啊小弟没好好学过背包只想出这个 C++ 32ms AC #include <cstdio> int main() { int C, N, a[11], w[11], i, j, k, p; while (scanf("%d", &C) != EOF) { int f[100001] = {0}; f[0] = 1; scanf("%d", &N); for (i = 1; i <= N; i++) { scanf("%d%d", &a[i], &w[i]); for (k = 100000; k; k--) if (k - w[i] >= 0 && f[k - w[i]]) for (p = k, j = 0; j < a[i]; j++) { if (p > 100000 || f[p] == i) break; f[p] = i; p += w[i]; } } for (i = C; !f[i]; i--); printf("%d\n", i); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator