标签:style blog color os io ar for div log
这个,属于动态规划内容,居然一次通过,呵呵!
/* ID: qq104801 LANG: 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: numtri LANG: C++ Compiling... Compile: OK Executing... 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 ---- 5 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 ------- test 2 ---- 2 1 2 3 ------- test 3 ---- 1 0 ------- test 4 ---- 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 99 ------- test 5 ---- 15 46 30 82 90 56 17 95 15 48 26 4 58 71 79 92 60 12 21 63 47 19 41 90 85 14 9 52 71 79 16 81 51 95 93 34 10 79 95 61 92 89 88 66 64 92 63 66 64 39 51 27 0 95 12 8 66 47 42 74 69 89 83 66 41 90 78 65 79 90 33 53 29 85 22 33 37 36 68 60 58 36 60 42 42 67 15 16 18 56 79 8 59 61 97 55 81 75 40 90 1 37 35 43 67 12 11 33 93 54 53 26 18 86 70 84 14 31 99 86 30 ------- test 6 ---- 199 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 。。。。。。。。。。。。。。。。
标签:style blog color os io ar for div log
原文地址:http://www.cnblogs.com/dpblue/p/3950441.html