杭電hdu 1248 寒冰王座 完全揹包

http://acm.hdu.edu.cn/showproblem.php?pid=1248

注意與0-1揹包的區別

#include <stdio.h>
#include <string.h>

int max(int a, int b)
{
	return a > b ? a : b;
}

int main()
{
	int t;
	int n;
	int arr[3] = {150, 200, 350};
	int i, j;
	int dp[10002];
	scanf("%d", &t);
	while(t --){
		scanf("%d", &n);
		memset(dp, 0, sizeof(dp));
		for(i = 0; i < 3; i ++){
			for(j = arr[i]; j <= n; j ++){
				dp[j] = max(dp[j], dp[j - arr[i]] + arr[i]);
			}
		}
		printf("%d\n", n - dp[n]);
	}
	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章