首页 > 代码库 > usaco-2.2-nocows-passed
usaco-2.2-nocows-passed
呵呵,搞了半天,也没有搞明白,网上参考了一下成功者,下来再仔细研究下。
/*ID: qq104801LANG: 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: nocowsLANG: C++Compiling...Compile: OKExecuting... 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 77Keep up the good work!Thanks for your submission!
usaco-2.2-nocows-passed
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。