| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我也没优化啊,,,就0ms了,,In Reply To:W可变的完全背包问题 为啥我的还需要63MS?求优化技巧 Posted by:abilitytao at 2010-03-08 20:38:41 #include <iostream>
#include <cmath>
using namespace std;
const int N=1000*46;
#define max(a,b) ((a>b)?(a):(b))
int a[11],b[11],dp[N];
int main()
{
int t;
for(scanf("%d",&t);t--;)
{
int money,year;
scanf("%d%d",&money,&year);
int v=money*pow(1.1,(double)year)/1000;
int d;
scanf("%d",&d);
int i,j;
for(i=1;i<=d;i++)
scanf("%d%d",&a[i],&b[i]);
memset(dp,0,sizeof(dp));
for(i=1;i<=d;i++)
for(j=a[i]/1000;j<=v;j++)
dp[j]=max(dp[j-a[i]/1000]+b[i],dp[j]);
for(i=1;i<=year;i++)
money+=dp[money/1000];
printf("%d\n",money);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator