hdu 2525 Clone Wars

http://acm.hdu.edu.cn/showproblem.php?pid=2525

WA了很多次,从网上档的代码,留着自己慢慢悟

View Code
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 
 5 
 6 int N, D, A, K, X;
 7 // 保留两个信息,即当天克隆人已经生存的天数
 8 // 以及正在培育中的人已经培育的天数
 9 // 由于天数最多只有100天,所以我们可以使用数组来进行模拟 
10 
11 __int64 P[105], W[105]; // P表示克隆人信息,W表示培育的信息
12 
13 void init() {
14     memset(P, 0, sizeof (P));
15     memset(W, 0, sizeof (W));
16     P[0] = N; // 表示有N个人已经存活了0天
17 }
18 
19 void updateday() {
20     for (int i = D; i >= 0; --i) {
21         P[i+1] = P[i];
22     }
23     for (i = K; i >= 0; --i) {
24         W[i+1] = W[i];
25     }
26     P[0] = W[K];
27 }
28 
29 void collect() { // 每天例行任务,收集克隆体种子 
30     W[0] = 0;
31     for (int i = 1; i <= A; ++i) {
32         W[0] += P[i];
33     }
34 }
35 
36 int main() {
37     int T;
38     scanf("%d", &T);
39     while (T--) {
40         __int64 cnt = 0;
41         scanf("%d %d %d %d %d", &N, &D, &A, &K, &X);
42         init();
43         for (int i = 1; i <= X; ++i) { // 更新到要询问的天数 
44             updateday();
45             collect(); 
46             for (int i = 1; i <= D; ++i) {
47                 cnt += P[i];
48             }
49         }
50         printf("%I64d\n", cnt * 5);
51     }
52     return 0;    
53 }
原文地址:https://www.cnblogs.com/zlyblog/p/3060637.html