比赛 20111108 评测结果 AAAWWWWWWW
题目名称 分裂 最终得分 30
用户昵称 fanzeyi 运行时间 0.000 s
代码语言 C 内存使用 0.00 MiB
提交时间 2011-11-08 12:30:44
显示代码纯文本
  1. /*
  2. ID: fanzeyi1
  3. LANG: C
  4. TASK: mushroom
  5. */
  6. /*
  7. * =====================================================================================
  8. *
  9. * Filename: mushroom.c
  10. * Version: 1.0
  11. * Created: 11/08/2011 09:43:17 AM
  12. * Revision: none
  13. * Compiler: gcc
  14. * Author: Zeray Fan, fanzeyi1994[at]gmail.com
  15. * Company: http://www.fanhe.org/
  16. *
  17. * =====================================================================================
  18. */
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22.  
  23. unsigned long long mushroom[2][20000];
  24.  
  25. int main(void) {
  26. FILE *fin = fopen("mushroom.in","r");
  27. FILE *fout = fopen("mushroom.out", "w");
  28. int i;
  29. int n;
  30. int max;
  31. int tmp;
  32. int time;
  33. unsigned long long result;
  34. fscanf(fin, "%d", &n);
  35. max = 2;
  36. memset(mushroom, 0, sizeof(mushroom));
  37. mushroom[0][2] = 1;
  38. for( time = 0 ; time < n ; time++ ) {
  39. tmp = max;
  40. memset(mushroom[(time&1)^1], 0, sizeof(mushroom[0]));
  41. for( i = 1 ; i <= max ; i++ ) {
  42. if(i == 1 && mushroom[time&1][i]) {
  43. mushroom[(time&1)^1][2] += mushroom[time&1][1];
  44. continue;
  45. }
  46. if(mushroom[time&1][i]) {
  47. mushroom[(time&1)^1][i+1] += mushroom[time&1][i];
  48. mushroom[(time&1)^1][i-1] += mushroom[time&1][i];
  49. if(i + 1 > tmp) {
  50. tmp = i + 1;
  51. }
  52. }
  53. }
  54. max = tmp;
  55. }
  56. result = 0;
  57. for( i = 1 ; i <= max ; i++ ) {
  58. result = result + mushroom[(n&1)^1][i];
  59. }
  60. fprintf(fout, "%llu\n", result);
  61. return 0;
  62. }