记录编号 223981 评测结果 AAAAAAAAAA
题目名称 [HNOI 2004] 邮递员 最终得分 100
用户昵称 Gravatar葳棠殇 是否通过 通过
代码语言 C++ 运行时间 0.108 s
提交时间 2016-02-15 09:24:11 内存使用 1.65 MiB
显示代码纯文本
  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. using namespace std;
  5. #define W(i) ((i-1)<<1)
  6. #define mod 100000000
  7. #define LL long long
  8. struct BIGNUM{
  9. int a[15];
  10. BIGNUM(){memset(a,0,sizeof(a));}
  11. friend BIGNUM operator +(BIGNUM a,BIGNUM b){
  12. BIGNUM c;
  13. int x=0;
  14. c.a[0]=max(a.a[0],b.a[0])+1;
  15. for(int i=1;i<=c.a[0];i++){
  16. c.a[i]=a.a[i]+b.a[i]+x;
  17. x=c.a[i]/mod;
  18. c.a[i]%=mod;
  19. }
  20. while(c.a[0]&&!c.a[c.a[0]]){
  21. c.a[0]--;
  22. }
  23. return c;
  24. }
  25. void out(){
  26. printf("%d",a[a[0]]);
  27. a[0]--;
  28. while(a[0]>0){
  29. printf("%08d",a[a[0]--]);
  30. }
  31. printf("\n");
  32. }
  33. }ans,tmps;
  34. BIGNUM sum[2][10007];
  35. int hash[10007],tot[2];
  36. LL state[2][10007];
  37. int n,m,k=1;
  38. void push(LL sta){
  39. int pos=sta%10007;
  40. while(hash[pos]){
  41. if(state[k^1][hash[pos]]==sta){
  42. sum[k^1][hash[pos]]=sum[k^1][hash[pos]]+tmps;
  43. return;
  44. }
  45. pos++;
  46. if(pos==10007){
  47. pos=0;
  48. }
  49. }
  50. tot[k^1]++;
  51. hash[pos]=tot[k^1];
  52. sum[k^1][tot[k^1]]=tmps;
  53. state[k^1][tot[k^1]]=sta;
  54. }
  55. int main(){
  56. freopen("postman.in","r",stdin);
  57. freopen("postman.out","w",stdout);
  58. scanf("%d%d",&m,&n);
  59. if(n==1||m==1){
  60. printf("1\n");
  61. return 0;
  62. }
  63. sum[0][1].a[1]=sum[0][1].a[0]=1;
  64. tot[0]=1;
  65. for(int i=1;i<=n;i++){
  66. for(int j=1;j<=m;j++){
  67. k^=1;
  68. tot[k^1]=0;
  69. memset(hash,0,sizeof(hash));
  70. memset(state[k^1],0,sizeof(state[k^1]));
  71. memset(sum[k^1],0,sizeof(sum[k^1]));
  72. for(int s=1;s<=tot[k];s++){
  73. LL sta=state[k][s];
  74. tmps=sum[k][s];
  75. int p=(sta>>W(j))&3;
  76. int q=(sta>>W(j+1))&3;
  77. if(!p&&!q){
  78. if(i==n||j==m){
  79. continue;
  80. }
  81. sta^=1<<W(j);
  82. sta^=(1<<W(j+1))*2;
  83. push(sta);
  84. continue;
  85. }
  86. if(p&&!q){
  87. if(i!=n){
  88. push(sta);
  89. }
  90. if(j==m){
  91. continue;
  92. }
  93. sta^=(1<<W(j))*p;
  94. sta^=(1<<W(j+1))*p;
  95. push(sta);
  96. continue;
  97. }
  98. if(!p&&q){
  99. if(j!=m){
  100. push(sta);
  101. }
  102. if(i==n){
  103. continue;
  104. }
  105. sta^=(1<<W(j+1))*q;
  106. sta^=(1<<W(j))*q;
  107. push(sta);
  108. continue;
  109. }
  110. if(p==1&&q==1){
  111. int bracket=1;
  112. for(int v=j+2;v<=m+1;v++){
  113. int t=(sta>>(W(v)))&3;
  114. if(t==1){
  115. bracket++;
  116. }
  117. if(t==2){
  118. bracket--;
  119. }
  120. if(bracket==0){
  121. sta^=(1<<W(v))*2;
  122. sta^=(1<<W(v));
  123. break;
  124. }
  125. }
  126. sta^=1<<W(j);
  127. sta^=1<<W(j+1);
  128. push(sta);
  129. continue;
  130. }
  131. if(p==2&&q==2){
  132. int bracket=1;
  133. for(int v=j-1;v;v--){
  134. int t=(sta>>(W(v)))&3;
  135. if(t==2){
  136. bracket++;
  137. }
  138. if(t==1){
  139. bracket--;
  140. }
  141. if(bracket==0){
  142. sta^=(1<<W(v));
  143. sta^=(1<<W(v))*2;
  144. break;
  145. }
  146. }
  147. sta^=(1<<W(j))*2;
  148. sta^=(1<<W(j+1))*2;
  149. push(sta);
  150. continue;
  151. }
  152. if(p==1&&q==2){
  153. if(i==n&&j==m){
  154. ans=ans+tmps;
  155. }
  156. continue;
  157. }
  158. if(p==2&&q==1){
  159. sta^=(1<<W(j))*p;
  160. sta^=(1<<W(j+1))*q;
  161. push(sta);
  162. continue;
  163. }
  164. }
  165. }
  166. for(int j=1;j<=tot[k^1];j++){
  167. state[k^1][j]=state[k^1][j]<<2;
  168. }
  169. }
  170. ans=ans+ans;
  171. ans.out();
  172. }