USACO Section 3.1: Score Inflation

完全背包问题

 1 /*

 2 ID: yingzho1

 3 LANG: C++

 4 TASK: inflate

 5 */

 6 #include <iostream>

 7 #include <fstream>

 8 #include <string>

 9 #include <map>

10 #include <vector>

11 #include <set>

12 #include <algorithm>

13 #include <stdio.h>

14 #include <queue>

15 #include <cstring>

16 #include <cmath>

17 #include <list>

18 

19 using namespace std;

20 

21 ifstream fin("inflate.in");

22 ofstream fout("inflate.out");

23 

24 const int inf = 100000;

25 

26 struct cat {

27     int point;

28     int time;

29     cat(int a, int b) : point(a), time(b) { }

30     cat() : point(0), time(0) { }

31 };

32 

33 int total_time;

34 int N;

35 

36 int main()

37 {

38     fin >> total_time >> N;

39     vector<cat> pro(N);

40     for (int i = 0; i < N; i++) {

41         fin >> pro[i].point >> pro[i].time;

42     }

43     vector<int> f(total_time+1);

44     for (int i = 0; i < N; i++) {

45         for (int j = 1; j*pro[i].time < total_time; j++) {

46             for (int k = 0; j*pro[i].time+k <= total_time && k <= pro[i].time; k++) {

47                 /*if (f[j*pro[i].time+k] < f[(j-1)*pro[i].time+k]+pro[i].point) {

48                     f[j*pro[i].time+k] = f[(j-1)*pro[i].time+k]+pro[i].point;

49                     cout << "f[" << j*pro[i].time+k << "]: " << f[j*pro[i].time+k] << endl;

50                 }*/

51                 f[j*pro[i].time+k] = max(f[j*pro[i].time+k], f[(j-1)*pro[i].time+k]+pro[i].point);

52                 //cout << "f[" << j*pro[i].time+k << "]: " << f[j*pro[i].time+k] << endl;

53             }

54         }

55     }

56     fout << f[total_time] << endl;

57 

58     return 0;

59 }

 

你可能感兴趣的:(USACO)