标签:区间dp
3 2 3 2 1 1 2 1 3
1 3HintYou shouldn‘t print any space in each end of the line in the hack data.
#include<stdio.h> #include<iostream> #include<string.h> #include<math.h> using namespace std; const int N = 1005; #define LL __int64 int n,q,a[N],l,r,dp[N][N]; int main() { while(scanf("%d%d",&n,&q)>0){ for(int i=1; i<=n; i++) scanf("%d",&a[i]); memset(dp,0,sizeof(dp)); for(int k=1; k<n; k++) for(int i=1; i+k<=n; i++){ int j=i+k; dp[i][j]=dp[i][j-1]+dp[i+1][j]-dp[i+1][j-1]; if(a[i]>a[j]) dp[i][j]++; } while(q--){ scanf("%d%d",&l,&r); printf("%d\n",dp[l][r]); } } return 0; }
HDU 5273 Dylans loves sequence(区间DP)
标签:区间dp
原文地址:http://blog.csdn.net/u010372095/article/details/46575777