如题:http://poj.org/problem?id=2063
题目给出初始金额和年利率,要求求出在X年内的最大收益
本金都是1000的倍数所以1000000/1000=1000,(The value of a bond is always a multiple of $1 000.)加上每年的收益绝对是小于本金的,(The interest of a bond is never more than 10% of its value.)d<=10, year<=40 ) 所以1000*2*40=80000;
数组开个80000多就够。
然后每一年用一次完全背包,找出当前年收益最大。本金注意累加
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int c[12];
int w[12];
int f[80005];
int mon,y,up;
#define max(a,b)(a>b?a:b)
int main()
{
int T;
cin>>T;
while(T--)
{
scanf("%d%d",&mon,&y);
int i,j,k,d;
scanf("%d",&d);
for(i=1;i<=d;i++)
{
scanf("%d%d",&c[i],&w[i]);
c[i]/=1000;
}
int tmon=mon;
for(k=1;k<=y;k++)
{
mon=tmon/1000;
memset(f,0,sizeof(f));
for(i=1;i<=d;i++)
for(j=c[i];j<=mon;j++)
f[j]=max(f[j],f[j-c[i]]+w[i]);
tmon+=f[mon];
}
printf("%d\n",tmon);
}
}