UVA 105,640 Paths through the Hourglass

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.