"Algorithm Series learning" [Kuangbin you fly] topic 12 Basics DP1 G-Free pies

Source: Internet
Author: User
Tags cmath

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.