USACO 3.1 Score Inflation

TASK: inflate
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.000 secs, 3144 KB]
   Test 2: TEST OK [0.000 secs, 3144 KB]
   Test 3: TEST OK [0.000 secs, 3144 KB]
   Test 4: TEST OK [0.000 secs, 3144 KB]
   Test 5: TEST OK [0.000 secs, 3144 KB]
   Test 6: TEST OK [0.000 secs, 3144 KB]
   Test 7: TEST OK [0.054 secs, 3144 KB]
   Test 8: TEST OK [0.108 secs, 3144 KB]
   Test 9: TEST OK [0.189 secs, 3144 KB]
   Test 10: TEST OK [0.243 secs, 3144 KB]
   Test 11: TEST OK [0.000 secs, 3144 KB]
   Test 12: TEST OK [0.000 secs, 3144 KB]

All tests OK.

1 /*
2 PROG: inflate
3 ID: jiafeim1
4 LANG: C++
5  */
6 #include <algorithm>
7 #include <iostream>
8 #include <fstream>
9
10 long point[10002]={0};
11
12 long item[10002][2];
13 int top=0;
14 using namespace std;
15
16 long total_time;
17 long item_amount;
18
19 #define maxN(x,y) ((x)>(y)?(x):(y))
20 int main()
21 {
22 std::ifstream fin("inflate.in");
23 std::ofstream fout("inflate.out");
24
25 fin>>total_time>>item_amount;
26
27 for(int i = 0;i!=item_amount;++i)
28 {
29 fin>>item[i][0]>>item[i][1];
30 }
31
32 for(int i = 0;i!=item_amount;++i)
33 {
34 for(int t =item[i][1] ;t<=total_time;++t)
35 {
36 point[t] = maxN(point[t],point[t-item[i][1]]+item[i][0]);
37 }
38 }
39 fout<<point[total_time]<<endl;
40
41 fin.close();
42 fout.close();
43 return 0;
44 }
posted @ 2011-05-09 11:23  幻魇  阅读(238)  评论(0编辑  收藏  举报