标签:style blog http color io os ar for sp
简单dp
//简单的dp #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int dp[110][110];//dp[i][j] di i ceng di j ge zui da he int a[110][110]; int main() { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ scanf("%d",&a[i][j]); } } memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) { for(int j=1;j<=i;j++) { dp[i][j]=a[i][j]+max(dp[i-1][j-1],dp[i-1][j]); } } int ans=-1; for(int i=1;i<=n;i++)ans=max(ans,dp[n][i]); printf("%d\n",ans); } return 0; }
标签:style blog http color io os ar for sp
原文地址:http://www.cnblogs.com/laiba2004/p/4005648.html