usaco-3.2-kimbits-pass
就这个比较清晰:
/* ID: qq104801 LANG: C++ TASK: kimbits */ #include <iostream> #include <fstream> #include <cstring> #include <vector> #include <map> #include <list> #include <set> #include <queue> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; #define NMAX 35 int a[NMAX][NMAX]; int d[NMAX][NMAX]; void test() { freopen("kimbits.in","r",stdin); freopen("kimbits.out","w",stdout); int n,l; long long x; cin>>n>>l>>x; int i,j; for(i=0;i<=n;i++){ a[i][0]=1; d[i][0]=1; } for(i=0;i<=l;i++) d[0][i]=1; for(i=1;i<=n;i++) { d[i][0]=1; for(j=1;j<=l;j++) { a[i][j]=a[i-1][j]+a[i-1][j-1]; d[i][j]=a[i][j]+d[i][j-1]; } } j=l; int leave=x-1; for(i=n-1;i>=0;i--) { if(leave>=d[i][j]) { leave-=d[i][j]; j--; cout<<1; } else cout<<0; } cout<<endl; } int main () { test(); return 0; }
test data:
USACO Training Grader Results 4 users online CHN/2 USA/2 USER: cn tom [qq104801] TASK: kimbits LANG: C++ Compiling... Compile: OK Executing... Test 1: TEST OK [0.005 secs, 3380 KB] Test 2: TEST OK [0.003 secs, 3380 KB] Test 3: TEST OK [0.003 secs, 3380 KB] Test 4: TEST OK [0.003 secs, 3380 KB] Test 5: TEST OK [0.005 secs, 3380 KB] Test 6: TEST OK [0.005 secs, 3380 KB] Test 7: TEST OK [0.005 secs, 3380 KB] Test 8: TEST OK [0.005 secs, 3380 KB] Test 9: TEST OK [0.005 secs, 3380 KB] Test 10: TEST OK [0.005 secs, 3380 KB] Test 11: TEST OK [0.008 secs, 3380 KB] Test 12: TEST OK [0.005 secs, 3380 KB] Test 13: TEST OK [0.005 secs, 3380 KB] All tests OK. Your program ('kimbits') produced all correct answers! This is your submission #6 for this problem. Congratulations! Here are the test data inputs: ------- test 1 ---- 4 2 1 ------- test 2 ---- 1 1 2 ------- test 3 ---- 8 4 30 ------- test 4 ---- 10 2 56 ------- test 5 ---- 7 7 64 ------- test 6 ---- 18 3 300 ------- test 7 ---- 21 10 1048576 ------- test 8 ---- 24 20 12936478 ------- test 9 ---- 31 24 10000000 ------- test 10 ---- 31 31 2147483648 ------- test 11 ---- 31 26 12345678 ------- test 12 ---- 31 26 123456789 ------- test 13 ---- 31 26 1234567890 Keep up the good work! Thanks for your submission!
/***********************************************
看书看原版,原汁原味。
不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。
没有原书,也要网上找PDF来看。
网上的原版资料多了去了,下载东西也到原始下载点去看看。
你会知其所以然,呵呵。
***********************************************/