标签:des style blog class code c
Time Limit: 3000MS | Memory Limit: 30000K | |
Total Submissions: 27580 | Accepted: 9335 |
Description
Input
Output
Sample Input
3 10 1 2 4 2 1 1 2 5 1 4 2 1 0 0
Sample Output
8 4
Source
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 6 using namespace std; 7 8 const int MAX_N = 105; 9 const int MAX_M = 1e5 + 7; 10 int N, M; 11 int v[MAX_N], c[MAX_N]; 12 int dp[MAX_M]; 13 14 void solve() { 15 dp[0] = 0; 16 for(int i = 1; i <= N; ++i) { 17 for(int j = 0; j <= M; ++j) { 18 if(dp[j] >= 0) { 19 dp[j] = c[i]; 20 } 21 else if(j < v[i] || dp[j - v[i]] <= 0) { 22 dp[j] = -1; 23 } else { 24 dp[j] = dp[j - v[i]] - 1; 25 } 26 27 } 28 } 29 30 31 int ans = 0; 32 for(int i = 1; i <= M; ++i) { 33 ans += dp[i] >= 0; 34 //printf("%d ",dp[i]); 35 } 36 37 printf("%d\n", ans); 38 } 39 int main() 40 { 41 // freopen("sw.in", "r", stdin); 42 while(~scanf("%d%d", &N, &M) && (N + M)) { 43 memset(dp, -1, sizeof(dp)); 44 for(int i = 1; i <= N; ++i) { 45 scanf("%d", &v[i]); 46 } 47 for(int i = 1; i <= N; ++i) { 48 scanf("%d", &c[i]); 49 } 50 51 solve(); 52 } 53 //cout << "Hello world!" << endl; 54 return 0; 55 }
标签:des style blog class code c
原文地址:http://www.cnblogs.com/hyxsolitude/p/3726867.html