Los small nunnery Valley P1926 - Brush title army

Topic Portal

Problem-solving ideas:

Backpack 01 obtains start and exactly equal to or greater than the minimum time k, and with the remaining time to simulate greedy

AC Code:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm> 
 4 
 5 using namespace std;
 6 
 7 int n,m,k,r,t[11],w[11],v[11],f[151],sy,ans;
 8 
 9 int main() {
10     scanf("%d%d%d%d",&n,&m,&k,&r);
11     for(int i = 1;i <= n; i++)
12         scanf("%d",&t[i]);
13     for(int i = 1;i <= m; i++)
14         scanf("%d",&w[i]);
15     for(int i = 1;i <= m; i++)
16         scanf("%d",&v[i]);
17     for(int i = 1;i <= m; i++) 
18         for(int j = r;j >= w[i]; j--)
19             f[j] = max(f[j],f[j-w[i]] + v[i]);
20     for(int i = 1;i <= r; i++)    
21         if(f[i] > k) {
22             sy = r - i;
23             break;
24         }
25     sort(t+1,t+1+n);
26     for(int i = 1;i <= n; i++) {
27         sy -= t[i];
28         if(sy <= 0) break;
29         ans++;
30     }
31     printf("%d",ans);        
32     return 0;
33 }

 

Guess you like

Origin www.cnblogs.com/lipeiyi520/p/11986349.html