# BZOJ 1270 雷涛的小猫 dp

https://www.lydsy.com/JudgeOnline/problem.php?id=1270

dp[i][j] = max(dp[i][j + 1] , max{dp[k][i + delta] | k = 1...n})+ num[i][j]

 1 #include<bits/stdc++.h>
2 #define IOS ios::sync_with_stdio(false);//不可再使用scanf printf
3 #define Max(a, b) ((a) > (b) ? (a) : (b))//禁用于函数，会超时
4 #define Min(a, b) ((a) < (b) ? (a) : (b))
5 #define Mem(a) memset(a, 0, sizeof(a))
6 #define Dis(x, y, x1, y1) ((x - x1) * (x - x1) + (y - y1) * (y - y1))
7 #define MID(l, r) ((l) + ((r) - (l)) / 2)
8 #define lson ((o)<<1)
9 #define rson ((o)<<1|1)
10 #define Accepted 0
11 #pragma comment(linker, "/STACK:102400000,102400000")//栈外挂
12 using namespace std;
13 inline int read()
14 {
15     int x=0,f=1;char ch=getchar();
16     while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
17     while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
18     return x*f;
19 }
20
21 typedef long long ll;
22 const int maxn = 2000 + 10;
23 const int MOD = 1000000007;//const引用更快，宏定义也更快
24 const int INF = 1e9 + 7;
25 const double eps = 1e-6;
26
27 int dp[maxn][maxn];
28 int num[maxn][maxn];//柿子数量
29 int Max[maxn];//每一高度的最大值
30
31 int main()
32 {
33     int n, h, delta;
34     scanf("%d%d%d", &n, &h, &delta);
35     for(int i = 1; i <= n; i++)
36     {
37         int m, x;
38         scanf("%d", &m);
39         while(m--)
40         {
41             scanf("%d", &x);
42             num[i][x]++;
43         }
44     }
45     for(int i = 1; i<= n; i++)dp[i][h] = num[i][h], Max[h] = max(Max[h], dp[i][h]);
46     for(int i = h - 1; i >= 1; i--)
47     {
48         for(int j = 1; j <= n; j++)
49         {
50             dp[j][i] = dp[j][i + 1] + num[j][i];
51             if(i + delta <= h)dp[j][i] = max(dp[j][i], Max[i + delta] + num[j][i]);
52             Max[i] = max(Max[i], dp[j][i]);
53         }
54     }
55     printf("%d\n", Max[1]);
56     return Accepted;
57 }

posted @ 2018-09-20 17:55  _努力努力再努力x  阅读(277)  评论(0编辑  收藏  举报