| ||||||||||
| 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 | |||||||||
求解,代码如下,老是RE,数组开大了就超内存。求高手解答#include <stdio.h>
typedef int count;
typedef struct
{
int a;
int b;
}m;
m a[15];
int dt[3000000];
int year,d;
int dp (int sum)
{
int i=0,max=0;
if(dt[sum]!=0)
return dt[sum];
for (i=0;i<d;i++)
{
if(sum-a[i].a>=0)
{
dt[sum-a[i].a]=dp(sum-a[i].a);
if(dt[sum-a[i].a]+a[i].b>max)
max=dt[sum-a[i].a]+a[i].b;
}
}
return max;
}
int main()
{
int sum;
count i,n;
while(scanf("%d",&n)!=EOF)
{
while(n--)
{
for (i=0;i<3000000;i++)
dt[i]=0;
scanf("%d%d",&sum,&year);
scanf("%d",&d); //d为可行投资方案
for (i=0;i<d;i++)
scanf("%d%d",&a[i].a,&a[i].b);
for (i=0;i<year;i++)
sum += dp(sum);
printf("%d\n",sum);
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator