杭电acm1248

背包问题http://love-oriented.com/pack/Index.html

虽然我不知道这是个什么网站。但这题是完全背包问题了。

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

int max(int a, int b);

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

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


posted @ 2015-10-11 16:33  StevenLuke  阅读(129)  评论(0)    收藏  举报