Interval DP
/************************************************author:guanjuncreated time:2016/6/30 23:24:27File Name: 1025.cpp*************************************************/#include<iostream>#include<cstring>#include<cstdlib>#include<stdio.h>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<iomanip>#include<list>#include<deque>#include<stack>#defineull unsigned long Long#definell Long Long#defineMoD 90001#defineINF 0x3f3f3f3f#defineMAXN 10010#defineCLE (a) memset (A,0,sizeof (a))Constull inf = 1LL << A;Const Doubleeps=1e-5;using namespaceStd;priority_queue<int,vector<int>,greater<int> >PQ;structnode{intx, y;};structcmp{BOOL operator() (Node A,node b) {if(a.x==b.x)returnA.y>b.y; returnA.x>b.x; }};BOOLcmpintAintb) { returnA>b;} ll dp[ -][ -];Chars[ -];intMain () {#ifndef Online_judge freopen ("In.txt","R", stdin); #endif //freopen ("OUT.txt", "w", stdout); intT; CIN>>T; for(intt=1; t<=t;t++) {scanf ("%s", s+1); intN=strlen (s+1); CLE (DP); for(intlen=1; len<=n;len++){ for(intI=1; i+len-1<=n;i++){ intj=i+len-1; DP[I][J]+=dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]; if(S[i]==s[j]) dp[i][j]+=dp[i+1][j-1]+1; }} printf ("Case %d:%lld\n", t,dp[1][n]); } return 0;}
Lightoj 1025-the Specials Menu