usaco-2.3-nocows-passed
呵呵,搞了半天,也没有搞明白,网上参考了一下成功者,下来再仔细研究下。
/* ID: qq104801 LANG: C++ TASK: nocows */ #include <iostream> #include <fstream> #include <string> #include <vector> #include <cstdio> #include <algorithm> using namespace std; int n,k; int d[201][101]; void test() { freopen("nocows.in","r",stdin); freopen("nocows.out","w",stdout); cin>>n>>k; d[1][0]=1;d[1][1]=1; int i,j,p,q,res=0; for(i=3;i<=n;i+=2) { int upper=i>>1; for(j=1;j<=upper;j+=2) for(p=1;p<=d[j][0];++p) for(q=1;q<=d[i-1-j][0];++q) { if(d[j][p] && d[i-1-j][q]) { int height=(p>q?p:q)+1; if(height>d[i][0]) d[i][0]=height; res=(d[j][p]*d[i-1-j][q])<<1; if(i-1-j==j) res>>=1; d[i][height]=(d[i][height]+res)%9901; } } } cout<<d[n][k]%9901<<endl; } int main () { test(); return 0; }
test data:
USER: cn tom [qq104801] TASK: nocows LANG: C++ Compiling... Compile: OK Executing... Test 1: TEST OK [0.003 secs, 3448 KB] Test 2: TEST OK [0.003 secs, 3448 KB] Test 3: TEST OK [0.003 secs, 3448 KB] Test 4: TEST OK [0.008 secs, 3448 KB] Test 5: TEST OK [0.005 secs, 3448 KB] Test 6: TEST OK [0.011 secs, 3448 KB] Test 7: TEST OK [0.027 secs, 3448 KB] Test 8: TEST OK [0.022 secs, 3448 KB] Test 9: TEST OK [0.024 secs, 3448 KB] Test 10: TEST OK [0.022 secs, 3448 KB] Test 11: TEST OK [0.038 secs, 3448 KB] Test 12: TEST OK [0.043 secs, 3448 KB] All tests OK. YOUR PROGRAM ('nocows') 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 3 ------- test 2 ---- 9 4 ------- test 3 ---- 35 7 ------- test 4 ---- 15 4 ------- test 5 ---- 75 47 ------- test 6 ---- 99 15 ------- test 7 ---- 172 44 ------- test 8 ---- 165 65 ------- test 9 ---- 177 57 ------- test 10 ---- 198 56 ------- test 11 ---- 199 99 ------- test 12 ---- 199 77 Keep up the good work! Thanks for your submission!
/***********************************************
看书看原版,原汁原味。
不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。
没有原书,也要网上找PDF来看。
网上的原版资料多了去了,下载东西也到原始下载点去看看。
你会知其所以然,呵呵。
***********************************************/
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步