TYVJ 1005 采药 by C++

 1 #include<iostream>
 2 using namespace std;
 3 const int maxn=100;
 4 int t,n;
 5 int c[maxn]={0},w[maxn]={0},f[maxn]={0};
 6 void get_input()
 7 {
 8     cin >> t >> n;
 9     for (int i=0;i<n;i++) cin >> c[i] >>w[i];
10 }
11 void pack()
12 {
13     for (int i=0;i<n;i++){
14         for (int j=t;j>=c[i];j--){
15             if (f[j]<f[j-c[i]]+w[i]) f[j]=f[j-c[i]]+w[i];
16         }
17     }
18 }
19 int main()
20 {
21     get_input();
22     pack();
23     cout << f[t] << endl;
24     return 0;
25 }

看来C++的语法风格要慢慢来适应

posted @ 2012-07-04 18:14  NoRush  阅读(568)  评论(0编辑  收藏  举报