标签:alt printf queue algorithm 注释 main abs onclick 分享图片
dp水题
题解见代码注释
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <algorithm> 6 #include <queue> 7 #include <vector> 8 #define min(a, b) ((a) < (b) ? (a) : (b)) 9 #define max(a, b) ((a) > (b) ? (a) : (b)) 10 #define abs(a) ((a) < 0 ? (-1 * (a)) : (a)) 11 inline void swap(int &a, int &b) 12 { 13 int tmp = a;a = b;b = tmp; 14 } 15 inline void read(int &x) 16 { 17 x = 0;char ch = getchar(), c = ch; 18 while(ch < ‘0‘ || ch > ‘9‘) c = ch, ch = getchar(); 19 while(ch <= ‘9‘ && ch >= ‘0‘) x = x * 10 + ch - ‘0‘, ch = getchar(); 20 if(c == ‘-‘) x = -x; 21 } 22 23 const int INF = 0x3f3f3f3f; 24 const int MAXN = 5000 + 10; 25 26 //dp[i][j]表示当前高度为i,在第j颗树上的最大数量 27 //ma[i]表示在高度为i时的最大数量 28 //dp[i][j] = max(dp[i - 1][j], ma[i - delta]) + val[i][j] 29 //ma[i] = max(ma[i], ma[j]) 30 31 int dp[MAXN], ma[MAXN], val[MAXN][MAXN], n, h, delta; 32 33 int main() 34 { 35 read(n), read(h), read(delta); 36 for(register int i = 1;i <= n;++ i) 37 { 38 int tmp;read(tmp); 39 for(register int j = 1;j <= tmp;++ j) 40 { 41 int tt; 42 read(tt); 43 ++ val[tt][i]; 44 } 45 } 46 int ans = 0; 47 for(register int i = 1;i <= h;++ i) 48 for(register int j = n;j >= 1;-- j) 49 { 50 if(i - delta >= 0) dp[j] = max(dp[j], ma[i - delta]); 51 dp[j] += val[i][j]; 52 ma[i] = max(ma[i], dp[j]); 53 ans = max(ans, dp[j]); 54 } 55 printf("%d", ans); 56 return 0; 57 }
BZOJ1270: [BeijingWc2008]雷涛的小猫
标签:alt printf queue algorithm 注释 main abs onclick 分享图片
原文地址:http://www.cnblogs.com/huibixiaoxing/p/7979631.html