The main effect of the topic:
There are n kinds of bonds to buy, each price is a (A is a multiple of 1000), the annual interest is B. A person with a total of money tot (tot is a multiple of 1000), ask him in y years, the maximum can have how much money?
Ideas:
Since both tot and a are multiples of 1000, all can be reduced by 1000 times times in calculation, saving memory and time.
According to greedy thinking, every year with a full backpack to find the year's maximum available interest, and then the next year with the interest after the total money to continue to calculate ...
Code:
#include <iostream> #include <queue> #include <stack> #include <cstdio> #include <cstr ing> #include <cmath> #include <map> #include <set> #include <string> #define MP Make_pai
R #define SQ (x) ((x) * (x)) typedef int Int64;
Const double PI = ACOs (-1.0);
const int INF = 0X3F3F3F3F;
using namespace Std;
const int MOD = 1000000007;
const int MAXN = 13;
const int ADD = 1000*100;
int tot, y,n;
int C[MAXN], W[MAXN];
int f[100030];
int main () {int ncase;
scanf ("%d", &ncase);
while (ncase--) {scanf ("%d%d%d", &tot, &y, &n);
for (int i=0; i<n; ++i) {scanf ("%d%d", &c[i], &w[i]);
C[i]/= 1000;
for (int i=0; i<y; ++i) {for (int j=0; j<=tot/1000; ++j) f[j] = 0; for (int j=0; j<n; ++j) {for (intV=C[J]; v<=tot/1000;
++V) F[v] = max (F[v], f[v-c[j]]+w[j]);
} tot + = f[tot/1000];
printf ("%d\n", tot);
return 0; }
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/