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 |
就会写点简单的dp#include <stdio.h> #define MAXSIZE 101 #define max(a,b) (a)>(b)?(a):(b) int arr[MAXSIZE][MAXSIZE]; int dp[MAXSIZE][MAXSIZE]={0}; int n; int main() { int i,j,sum=0; scanf("%d",&n); for(i=0;i<n;i++) for(j=0;j<=i;j++) { scanf("%d",&arr[i][j]); } for(i=n-1;i>=0;i--) for(j=0;j<=i;j++) dp[i][j]=max(dp[i+1][j]+arr[i][j],dp[i+1][j+1]+arr[i][j]); sum=dp[0][0]; printf("%d\n",sum); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator