标签:mem 技术 code col color size cstring for image
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 using namespace std; 6 7 8 const int max_n = 100 + 2; 9 const int max_a = 1e5 + 10; 10 const int max_m = 1e5 + 10; 11 const int max_K = 1e5 + 10; 12 13 int n,K; 14 int a[max_n],m[max_n]; 15 int dp[max_K]; 16 17 void solve() 18 { 19 memset(dp,-1,sizeof(dp)); 20 // 需重复利用数组 21 dp[0]=0; 22 for(int i=1;i<=n;++i) 23 { 24 for(int j=0;j<=K;++j) 25 { 26 if(dp[j]>=0) 27 { 28 dp[j]=m[i]; 29 } 30 else if(j<a[i] || dp[j-a[i]]<=0) 31 { 32 dp[j]=-1; 33 } 34 else 35 { 36 dp[j]=dp[ j-a[i] ] - 1; 37 } 38 } 39 } 40 41 if(dp[K]>=0) 42 { 43 printf("YES\n"); 44 } 45 else 46 { 47 printf("NO\n"); 48 } 49 } 50 51 int main() 52 { 53 scanf("%d %d",&n,&K); 54 for(int i=1;i<=n;++i) 55 { 56 scanf("%d",&a[i]); 57 } 58 for(int i=1;i<=n;++i) 59 { 60 scanf("%d",&m[i]); 61 } 62 solve(); 63 return 0; 64 } 65 66 67 /* 68 3 17 69 3 5 8 70 3 2 2 71 72 */
标签:mem 技术 code col color size cstring for image
原文地址:https://www.cnblogs.com/jishuren/p/12259470.html