Disclaimer: This article is a blogger original article, do not reprint without permission.
Classic title question number (reproduced here):
Easy:
1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1414, 1456, 145 8,
1609, 1644, 1664, 1690, 1699, 1740,1742, 1887, 1926, 1936, 1952, 1953, 1958, 1959, 1962, 1975, 1989, 2018 ,
Not easy:
1019, 1037, 1080, 1112, 1141, 1170, 1192, 1239, 1655, 1695, 1707, 1733 (interval subtraction plus check set)
1737, 1837, 1850, 1920x1080(Reinforced Han Rota),1934(all longest common subsequence), 1964(maximum rectangular area, O (n*m) algorithm), 2138, 2151, 2161, 2178,
Recommended:
1015, 1635, 1636(very good), 1671, 1682, 1692(optimization), 1704, 1717, 1722, 1726, 1732 , 1770,
1821, 1853, 1949, 2019, 2127, 2176, 2228, 2287, 2342, 2374, 2378, 2384 , 2411
1.POJ 1050 to the Max
"Algorithm Analysis" the largest continuous sub-segment and the expansion, the beginning and end of the block, the beginning of the line, the number of the middle of the end line of the matrix of each column, can be compressed into a one-dimensional array, and then the maximum consecutive sub-segments and output the maximum answer can be.
1#include <cstdio>2#include <cstring>3 using namespacestd;4 inta[ the][ the],mat[ the],n,ans=-1e8;5 intdp () {6 intdp[ the],t=-1e8;7Memset (DP,0,sizeof(DP));8dp[1]=mat[1];9 for(intI=2; i<=n;i++)Ten if(dp[i-1]<0) dp[i]=Mat[i]; One Elsedp[i]=dp[i-1]+Mat[i]; A for(intI=1; i<=n;i++) - if(dp[i]>t) t=Dp[i]; - returnT; the } - intMain () { -scanf"%d",&n); - for(intI=1; i<=n;i++) + for(intj=1; j<=n;j++) scanf ("%d",&a[i][j]); - for(intI=1; i<=n;i++) + for(intj=i;j<=n;j++){ AMemset (Mat,0,sizeof(MAT)); at for(intk=1; k<=n;k++) - for(intl=i;l<=j;l++) -mat[k]+=A[l][k]; - intt=DP (); - if(ans<t) ans=T; - } inprintf"%d", ans); - return 0; to}View Code
2.POJ 1088 Ski
"Algorithm Analysis" the largest ascending sub-sequence of two-dimensional expansion, using dp+ recursion to find the maximum sequence length of four directions, output the maximum answer can be.
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 intplus[4][2]={{-1,0},{0,-1},{1,0},{0,1}};6 intr,c,map[ the][ the],len[ the][ the],ans=0;7 intdpintXinty) {8 if(Len[x][y])returnLen[x][y];9 intmaxans=0, S;Ten for(intt=0;t<4; t++){ One inti=x+plus[t][0],j=y+plus[t][1]; A if(i&&j&&i<=r&&j<=c&&map[i][j]<Map[x][y]) { -s=DP (I,J); - if(S>maxans) maxans=s; the } - } -len[x][y]=maxans+1; - returnLen[x][y]; + } - intMain () { +scanf"%d%d",&r,&c); Amemset (Len,0,sizeof(len)); at for(intI=1; i<=r;i++) - for(intj=1; j<=c;j++) -scanf"%d",&map[i][j]); - for(intI=1; i<=r;i++) - for(intj=1; j<=c;j++){ -len[i][j]=DP (I,J); in if(Len[i][j]>ans) ans=Len[i][j]; - } toprintf"%d", ans); + return 0; -}View Code
POJ topic of dynamic planning