sdut2852 小鑫去爬山9dp入门)
2017-08-11 20:57 tlnshuju 阅读(264) 评论(0) 编辑 收藏 举报#include<stdio.h> int a[100][100]; int main() { int n; while(scanf("%d",&n)!=EOF) { for(int i=1;i<=n;i++) for(int j=1;j<=i;j++) scanf("%d",&a[i][j]); for(int i=2;i<=n;i++){ int j=1; for(;j<=i;j++){ if(j == 1) a[i][j] += a[i-1][j]; else if(j == i) a[i][j] += a[i-1][j-1]; else if(a[i][j] + a[i-1][j] < a[i][j] + a[i-1][j-1]) a[i][j] += a[i-1][j]; else a[i][j] += a[i-1][j-1]; } } int minn=0; minn = a[n][1]; for(int i=1;i<=n;i++)if(a[n][i] < minn ) minn = a[n][i]; printf("%d\n",minn); } return 0; }