CSU 1640 机智的刷题方式

完全背包

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn = + ;
int dp[maxn];
const int INF = 0x7FFFFFFF; int main()
{
int A, B, C, H, X, i, T;
scanf("%d", &T);
while (T--)
{
scanf("%d%d%d", &A, &B, &C);
scanf("%d%d", &H, &X);
for (i = ; i <= + ; i++) dp[i] = INF;
dp[] = ;
for (i = ; i <= H + ; i++) dp[i] = min(dp[i], dp[i - ] + A);
for (i = ; i <= H + ; i++) dp[i] = min(dp[i], dp[i - ] + B);
for (i = ; i <= H + ; i++) dp[i] = min(dp[i], dp[i - ] + C);
int ans = INF;
for (i = H; i <= H + ; i++) if (ans > dp[i]) ans = dp[i];
printf("%d\n", ans);
memset(dp, , sizeof(dp));
for (i = A; i <= X; i++) dp[i] = max(dp[i], dp[i - A] + );
for (i = B; i <= X; i++) dp[i] = max(dp[i], dp[i - B] + );
for (i = C; i <= X; i++) dp[i] = max(dp[i], dp[i - C] + );
printf("%d\n", dp[X]);
}
return ;
}
上一篇:leetcode第一刷_Maximum Depth of Binary Tree


下一篇:日志记录到txt文件