Usaco-numtri-pass!

Source: Internet
Author: User

 

This is the content of dynamic planning. It was approved once!

/*ID: qq104801LANG: C++TASK: numtri*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <assert.h>#define max(a,b) (a>b?a:b)int r;int a[1000][1000];int d[1000][1000];void test(){        FILE *fin = fopen ("numtri.in", "r");    FILE *fout = fopen ("numtri.out", "w");         fscanf(fin,"%d",&r);    //printf("%d\n",r);    int i,j;    for(i=0;i<r;i++)        for(j=0;j<=i;j++)        {            fscanf(fin,"%d",&a[i][j]);            //printf("%d ",a[i][j]);                    }        for(j=0;j<r;j++)    {        d[r-1][j]=a[r-1][j];        //printf("%d\n",d[r-1][i]);    }    for(i=r-2;i>=0;i--)        for(j=0;j<=i;j++)            d[i][j]=a[i][j]+max(d[i+1][j],d[i+1][j+1]);    fprintf(fout,"%d\n",d[0][0]);    fclose(fin);    fclose(fout);}main () {        test();        exit (0);}

Test results:

USER: ll tom [qq104801]TASK: numtriLANG: C++Compiling...Compile: OKExecuting...   Test 1: TEST OK [0.008 secs, 11308 KB]   Test 2: TEST OK [0.005 secs, 11308 KB]   Test 3: TEST OK [0.003 secs, 11308 KB]   Test 4: TEST OK [0.003 secs, 11308 KB]   Test 5: TEST OK [0.005 secs, 11308 KB]   Test 6: TEST OK [0.019 secs, 11308 KB]   Test 7: TEST OK [0.041 secs, 11308 KB]   Test 8: TEST OK [0.016 secs, 11308 KB]   Test 9: TEST OK [0.235 secs, 11308 KB]All tests OK.YOUR PROGRAM (‘numtri‘) WORKED FIRST TIME! That‘s fantastic -- and a rare thing. Please accept these special automated congratulations.Here are the test data inputs:------- test 1 ----573 88 1 02 7 4 44 5 2 6 5------- test 2 ----212 3------- test 3 ----10------- test 4 ----1011 11 1 11 1 1 11 1 1 1 11 1 1 1 1 11 1 1 1 1 1 11 1 1 1 1 1 1 11 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 99------- test 5 ----154630 8290 56 1795 15 48 264 58 71 79 9260 12 21 63 47 1941 90 85 14 9 52 7179 16 81 51 95 93 34 1079 95 61 92 89 88 66 64 9263 66 64 39 51 27 0 95 12 866 47 42 74 69 89 83 66 41 90 7865 79 90 33 53 29 85 22 33 37 36 6860 58 36 60 42 42 67 15 16 18 56 79 859 61 97 55 81 75 40 90 1 37 35 43 67 1211 33 93 54 53 26 18 86 70 84 14 31 99 86 30------- test 6 ----19910 10 1 00 1 0 10 1 0 1 00 1 0 1 0 10 1 0 1 0 1 00 1 0 1 0 1 0 10 1 0 1 0 1 0 1 00 1 0 1 0 1 0 1 0 10 1 0 1 0 1 0 1 0 1 00 1 0 1 0 1 0 1 0 1 0 10 1 0 1 0 1 0 1 0 1 0 1 00 1 0 1 0 1 0 1 0 1 0 1 0 10 1 0 1 0 1 0 1 0 1 0 1 0 1 0。。。。。。。。。。。。。。。。

 

Usaco-numtri-pass!

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.