syhd142 |
|
|||
日歷
統(tǒng)計(jì)
導(dǎo)航常用鏈接留言簿(2)隨筆檔案(23)文章分類(270)
文章檔案(122)我的豆瓣搜索最新評(píng)論
閱讀排行榜
評(píng)論排行榜 |
某群里有人吼是0/1背包,就去看了一下,果然很裸,順便就A了。 #include <stdio.h>
#include <string.h> #define MAXN 1005 int c[MAXN], vol[MAXN], val[MAXN]; int main() { int t, N, V; scanf("%d", &t); while(t--) { scanf("%d %d", &N, &V); for(int i = 0; i < N; i++) scanf("%d", &val[i]); for(int i = 0; i < N; i++) scanf("%d", &vol[i]); memset(c, 0, sizeof(c)); for(int i = 0; i < N; i++) { for(int j = V; j >= vol[i]; j--) { if(c[j] < c[j - vol[i]] + val[i]) c[j] = c[j - vol[i]] + val[i]; } } printf("%d\n", c[V]); } return 0; }
|
![]() |
|
Copyright © Fucker | Powered by: 博客園 模板提供:滬江博客 |