zoukankan      html  css  js  c++  java
  • hdu 2563 递推

    1. #include <stdio.h>
    2. #include <string>
    3. #include <iostream>
    4. #include <string.h>
    5. #include <map>
    6. #define MAX 30
    7. using namespace std;
    8. /*
    9. 一道很好的递推题,虽然思路是从discuss中获得,但是应该想简单些,从前一次走可获得,
    10. 每次向上走可以为下一次获得3步机会,而向左或者向右则只能由两种。
    11. */
    12. int main()
    13. {
    14. int two[MAX] = {0,2}, three[MAX] = {0,1}, result[MAX] = {0,3};
    15. for(int i=2; i<=20; i++)
    16. {
    17. two[i] = two[i-1] + three[i-1] *2;
    18. three[i] = three[i-1] + two[i-1];
    19. result[i] = two[i-1] * 2 + three[i-1] * 3;
    20. }
    21. int T;
    22. scanf("%d", &T);
    23. while(T--)
    24. {
    25. int n;
    26. scanf("%d", &n);
    27. printf("%d ", result[n]);
    28. }
    29. return 0;
    30. }
    31. /*
    32. Problem Description
    33. 在一无限大的二维平面中,我们做如下假设:
    34. 1、 每次只能移动一格;
    35. 2、 不能向后走(假设你的目的地是“向上”,那么你可以向左走,可以向右走,也可以向上走,但是不可以向下走);
    36. 3、 走过的格子立即塌陷无法再走第二次;
    37. 求走n步不同的方案数(2种走法只要有一步不一样,即被认为是不同的方案)。
    38. Input
    39. 首先给出一个正整数C,表示有C组测试数据
    40. 接下来的C行,每行包含一个整数n (n<=20),表示要走n步。
    41. Output
    42. 请编程输出走n步的不同方案总数;
    43. 每组的输出占一行。
    44. Sample Input
    45. 2
    46. 1
    47. 2
    48. Sample Output
    49. 3
    50. 7
    51. */





    附件列表

    • 相关阅读:
      使用android-ndk官方ndkbuild例子
      小米8如何root
      Ubuntu点击dash home就崩溃
      Python自定义排序
      adb命令
      sqoop数据导出导入命令
      Docker命令详解
      如何输出第二列相同的行
      如何使用Xmanager及VNC登录远程桌面
      搭建GoldenGate的单向复制环境
    • 原文地址:https://www.cnblogs.com/sober-reflection/p/20eb0f1eb92e75f03011152532b7fa1f.html
    Copyright © 2011-2022 走看看