Luo Gu UVA12563 Jin Ge Jin Qu hao solution to a problem

This question is actually a distortion title 01 backpack, the main idea is as follows: (remaining time> 0), as much as you sing without the light of the remaining time. So we can use dp [i] is indicated when the current i s, the maximum number of songs you can sing.

State transition equation: dp [k] = max (dp [k], dp [k-yy] +1); final output can sing a song number.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n,t,m,yy;
 4 int dp[100000];
 5 int main()
 6 {
 7     cin>>n;
 8     for(int i=1;i<=n;i++)
 9     {
10         memset(dp,0x8f,sizeof(dp));
11         cin>>m>>t;
12         dp[0]=0;
13         for(int j=1;j<=m;j++)
14         {
15             cin>>yy;
16             for(int k=t-1;k>=yy;k--)
17             {
18                 dp[k]=max(dp[k],dp[k-yy]+1);
19             }
20         }
21         int ans;
22         for(int j=ans=t-1;j>=0;j--)
23         {
24             if(dp[j]>dp[ans])ans=j;
25         }
26         cout<<"Case"<<" "<<i<<":"<<" "<<dp[ans]+1<<" "<<ans+678<<endl;
27     }
28     return 0;
29 }
请各位大佬斧正(Anyway, I do not know what that means treatise)

 

Guess you like

Origin www.cnblogs.com/handsome-zyc/p/11237327.html