#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
#define MAX 10050
int collect[MAX];int weight[3]={150,200,350};int limate;
int dp(int p)
{
if(p==limate)
{
collect[p]=p;
return collect[p];
}
//如果访问过
if(collect[p]!=-1)
{
return collect[p];
}
//访问
int cs;int tmax=-1;int i;
for(i=0;i<3;i++)
{
cs=p+weight[i];
if(cs<=limate)
{
int fmax=dp(cs);
if(fmax>tmax)
{
tmax=fmax;
}
}
}
collect[p]=tmax;
//如果什么都没有选择
if(collect[p]==-1)
{
collect[p]=p;
}
return collect[p];
}
void init()
{
int i;
for(i=0;i<MAX;i++)
{
collect[i]=-1;
}
}
int main()
{
//freopen("input.txt","r",stdin);
int T;
scanf("%d",&T);getchar();
while(T--)
{
init();
scanf("%d",&limate);getchar();
int p=0;
dp(p);
cout<<limate-collect[0]<<endl;
}
return 0;
}
hdoj 1248(背包问题)(动态规划)
最新推荐文章于 2022-02-24 21:13:59 发布