题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1248
思路:比较裸的完全背包
AC代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <queue> #include <stack> #include <map> #include <cstring> #include <climits> #include <cmath> #include <cctype> const int inf = 0x3f3f3f3f;//1061109567 typedef long long LL; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 using namespace std; int dp[10010]; int main() { memset(dp,0,sizeof(dp)); int a[3] = {150,200,350}; for(int i=0; i<3; i++) { for(int j=a[i]; j<=10000; j++) { dp[j] = max(dp[j],dp[j-a[i]]+a[i]); } } int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); printf("%d\n",n-dp[n]); } return 0; }