Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:超时代码,求指教

Posted by clooszhao at 2013-01-24 12:10:47 on Problem 1276
In Reply To:超时代码,求指教 Posted by:micro_gao at 2013-01-24 11:28:25
> #include<iostream>
> #include<cstdio>
> #include<cmath>
> #include<cstring>
> #include<string>
> using namespace std;
> int a[20],num[20];
> int dp[100005];
> int main()
> {
> 	int c,n,i,j,k;
> 	while(scanf("%d%d",&c,&n)==2)
>     {
>         memset(a,0,sizeof(a));
>         memset(num,0,sizeof(num));
>         memset(dp,0,sizeof(dp));
>         for(i=1;i<=n;i++) scanf("%d%d",&num[i],&a[i]);
>         for(i=1;i<=n;i++)
>             for(j=a[i];j<=c;j++)
>                 for(k=1;k<=num[i];k++)
>                 {
>                     if(j>=k*a[i])
>                     {
>                         dp[j]=max(dp[j],dp[j-k*a[i]]+k*a[i]);
>                     }
>                     else break;
>                 }
>         printf("%d\n",dp[c]);
>     }
>     return 0;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator