| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我的程序 裸的动态规划阿 不裸我还不会做 ^_^#include<stdio.h>
#define maxlong 102
int dp[maxlong][maxlong];
int num[maxlong];
int n,max;
int main()
{ int i,j,k,a1;
scanf("%d",&n);
scanf("%d",&a1);
dp[1][maxlong-1]=a1;
for(i=1;i<=n-1;i++)
{ k=0;
for(j=0;j<=i;j++)
scanf("%d",&num[j]);
for(j=0;j<maxlong;j++)
{
if(dp[i][j]>0)
{
if(dp[i+1][j-1]<dp[i][j]+num[k])
dp[i+1][j-1]=dp[i][j]+num[k];
if(dp[i+1][j]<dp[i][j]+num[k+1])
dp[i+1][j]=dp[i][j]+num[k+1];
k++;
}
}
}
max=0;
for(i=0;i<maxlong;i++)
if(dp[n][i]>max)
max=dp[n][i];
printf("%d\n",max);
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator