Although learned a little before, but still do not------now good follow petition 1.4 to learn about ——————
(1) Digital triangles
D (i,j) = max (d (I+1,J), D (i+1,j+1)) + a[i][j]
HDU 2084
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <Set>9#include <queue>Ten#include <algorithm> One using namespacestd; A -typedefLong LongLL; - Const intINF = (1<< -)-1; the Const intMod=1000000007; - Const intmaxn=1000005; - - intd[1005][1005],a[1005][1005]; + - intMain () { + intT; Ascanf"%d",&T); at while(t--){ - intN; -scanf"%d",&n); -memset (D,0,sizeof(d)); - for(inti =1; i<=n;i++) - for(intj =1; j<=i;j++) scanf ("%d",&a[i][j]); in - for(inti = n;i>=1; i--){ to for(intj =1; j<=i;j++) +D[I][J] = max (d[i+1][j],d[i+1][j+1]) +A[i][j]; - } theprintf"%d\n", d[1][1]); * } $ return 0;Panax Notoginseng}View Code
(2) nested rectangles
Build the diagram first, then D (i) = Max (d (j) + 1)
Nyoj 16
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <Set>9#include <queue>Ten#include <algorithm> One using namespacestd; A -typedefLong LongLL; - Const intINF = (1<< -)-1; the Const intMod=1000000007; - Const intmaxn=1000005; - - intg[1005][1005]; + intd[1005]; - intN; + A structnode{ at intx, y; - }A[MAXN]; - - intdpinti) { - int& ans =D[i]; - if(Ans >0)returnans; inAns =1; - for(intj =1; J <= n;j++) to if(G[i][j]) ans = max (ANS,DP (j) +1); + - returnans; the } * $ intWork () {Panax Notoginseng intres =-1; - for(inti =1; I <= n;i++) res =Max (RES,DP (i)); the returnRes; + } A the intMain () { + intT; -scanf"%d",&T); $ while(t--){ $scanf"%d",&n); - for(inti =1; I <= n;i++) scanf ("%d%d",&a[i].x,&a[i].y); -Memset (G,0,sizeof(g)); thememset (D,0,sizeof(d)); - Wuyi for(inti =1; I <= n;i++){ the for(intj =1; J <= n;j++){ - if((a[i].x > a[j].x && a[i].y > a[j].y) | | (a[i].x > A[j].y && a[i].y >a[j].x)) WuG[I][J] =1; - } About } $ -printf"%d\n", work ()); - } - return 0; A}View Code
Book Dynamic Planning