首页 > 代码库 > usaco-numtri-pass!
usaco-numtri-pass!
这个,属于动态规划内容,居然一次通过,呵呵!
/*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);}
测试结果:
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!
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。