Https://vjudge.net/contest/68966#problem/G
Positive Solution One:
Http://www.clanfei.com/2012/04/646.html
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <string>5#include <algorithm>6#include <cmath>7 #defineINF 0x3f3f3f3f8 using namespacestd;9 Const intmaxn=1e5+1;Ten inta[ One][MAXN]; One intdp[ One][MAXN]; A - BOOLCheckintx) - { the if(x>=0&&x<=Ten) - { - return 1; - } + return 0; - } + intMain () A { at intN,x,y,maxtime; - while(SCANF ("%d", &n) = =1&&N) - { -maxtime=-INF; -Memset (A,0,sizeof(a)); - for(intI=0; i<n;i++) in { -scanf"%d%d",&x,&y); toa[x][y]++; +Maxtime=Max (maxtime,y); - } theMemset (DP,0,sizeof(DP)); * for(inti=maxtime-1; i>=0; i--) $ {Panax Notoginseng for(intk=0; k<=Ten; k++) - { thedp[k][i]=dp[k][i+1]; + if(Check (K-1)) A { theDp[k][i]=max (dp[k][i],dp[k-1][i+1]); + } - if(Check (k +1)) $ { $Dp[k][i]=max (dp[k][i],dp[k+1][i+1]); - } -dp[k][i]+=A[k][i]; the } - }Wuyiprintf"%d\n", dp[5][0]); the } - return 0; Wu}
Positive Push
Positive solution Two:
http://blog.csdn.net/qq_32680617/article/details/51057963
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <string>5#include <algorithm>6#include <cmath>7 #defineINF 0x3f3f3f3f8 using namespacestd;9 Const intmaxn=1e5+5;Ten inta[ One][MAXN]; One intMain () A { - intn,x,y; - while(SCANF ("%d", &n) = =1&&N) the { -Memset (A,0,sizeof(a)); - intmaxtime=-INF; - for(intI=0; i<n;i++) + { -scanf"%d%d",&x,&y); +Maxtime=Max (maxtime,y); Aa[x][y]++; at } - for(inti=maxtime-1; i>=0; i--) - { - for(intk=0; k<=Ten; k++) - { - if(k==0) in { -A[k][i]+=max (a[k][i+1],a[k+1][i+1]); to } + Else - { theA[k][i]+=max (Max (a[k][i+1],a[k-1][i+1]), a[k+1][i+1]); * } $ }Panax Notoginseng } -printf"%d\n", a[5][0]); the } + return 0; A}
Reverse Push
RE:
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <string>5#include <algorithm>6#include <cmath>7 #defineINF 0x3f3f3f3f8 using namespacestd;9 Const intmaxn=1e5+5;Ten inta[ One][MAXN]; One intMain () A { - intn,x,y; - while(SCANF ("%d", &n) = =1&&N) the { -Memset (A,0,sizeof(a)); - intmaxtime=-INF; - for(intI=0; i<n;i++) + { -scanf"%d%d",&x,&y); +Maxtime=Max (maxtime,y); Aa[x][y]++; at } - for(inti=maxtime-1; i>=0; i--) - { - for(intk=0; k<=Ten; k++) - { - if(k==0) in { -A[k][i]+=max (a[k][i+1],a[k+1][i+1]); to } + Else - { theA[k][i]+=max (Max (a[k][i+1],a[k-1][i+1]), a[k+1][i+1]); * } $ }Panax Notoginseng } -printf"%d\n", a[5][0]); the } + return 0; A}
RE
This code is written in reverse, but do not know why re, see the array also did not cross the line ..... Put it here first .....
"Algorithm Series learning" [Kuangbin you fly] topic 12 Basics DP1 G-Free pies