Paths through the Hourglass
Time Limit: 3000MS Memory Limit:0KB 64bit IO Format:%lld &%llu
SubmitStatusPracticeUVA 10564
1#include <stdio.h>2#include <string.h>3 4 intn,s;5 Long Longdp[ -][ About][550];6 inta[ About][ -];7 8 intDintXintYintm)9 {Ten if(x>=2*n-1) One return 0; A intv=A[x][y]; - if(dp[x+1][y][m-v]>0) - { theprintf"L"); -D (x+1, y,m-v); - } - Else + { -printf"R"); +D (x+1, y+1, M-v); A } at return 0; - } - - intMain () - { - inti,j,k; in while(SCANF ("%d%d", &n,&s)! =EOF) - { to if(n==0&& s==0) + Break; -Memset (DP,0,sizeof(DP)); the for(i=1; i<=n;i++) * { $ for(j=i;j<=n;j++)Panax Notoginseng { -scanf"%d",&a[i][j]); the } + } A for(i=n+1; i<=2*n-1; i++) the { + for(j=n;j<=i;j++) - { $scanf"%d",&a[i][j]); $ } - } - the for(i=n;i<=2*n-1; i++) - {Wuyi intv=a[2*n-1][i]; thedp[2*n-1][i][v]=1; - } Wu for(i=n*2-2; i>n;i--) - { About for(j=n;j<=i;j++) $ { - intv=A[i][j]; - for(k=v;k<=s;k++) - { Adp[i][j][k]=dp[i+1][j][k-v]+dp[i+1][j+1][k-v]; + } the } - } $ for(i=n;i>=1; i--) the { the for(j=i;j<=n;j++) the { the intv=A[i][j]; - for(k=v;k<=s;k++) in { thedp[i][j][k]=dp[i+1][j][k-v]+dp[i+1][j+1][k-v]; the } About } the } the the Long LongCnt=0; + for(i=1; i<=n;i++) - { thecnt=cnt+dp[1][i][s];Bayi } theprintf"%lld\n", CNT); the for(i=1; i<=n;i++) - { - if(dp[1][i][s]>0) the { theprintf"%d", I-1); theD1, i,s); the Break; - } the } theprintf"\ n"); the }94 return 0; the}View Code
UVA 105,640 Paths through the Hourglass