hdu 2563 -统计问题 【递推关系】

统计问题

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6525    Accepted Submission(s): 3843

链接: hdu 2563
Problem Description
在一无限大的二维平面中,我们做如下假设:
1、  每次只能移动一格;
2、  不能向后走(假设你的目的地是“向上”,那么你可以向左走,可以向右走,也可以向上走,但是不可以向下走);
3、  走过的格子立即塌陷无法再走第二次;

求走n步不同的方案数(2种走法只要有一步不一样,即被认为是不同的方案)。
 
Input
首先给出一个正整数C,表示有C组测试数据
接下来的C行,每行包含一个整数n (n<=20),表示要走n步。
 
Output
请编程输出走n步的不同方案总数;
每组的输出占一行。
 
Sample Input
  
  
2 1 2
 
Sample Output
  
  
3 7
 

题意:   中文题目,题意就摆在这,我就不说啦~~~

分析:

这个题目比赛的时候我没想什么递推关系,很明显,数据不大,我完全可以打表啊,事实上,我这个题确实是dfs打表过的,1A,得到FB,然后赛后查看打表数据,我才发现递推关系 _zZ。

//打表代码
int vis[50][60];
void DFS(int x, int y, int step)
{
    if(step == N)
    {
        ans++;
        return;
    }
    if(!vis[x - 1][y])
    {
        vis[x - 1][y] = 1;
        DFS(x - 1, y, step + 1) ;
        vis[x - 1][y] = 0;
    }
    if(!vis[x][y - 1])
    {
        vis[x][y - 1] = 1;
        DFS(x, y - 1, step + 1);
        vis[x][y - 1] = 0;
    }
    if(!vis[x][y + 1])
    {
        vis[x][y + 1] = 1;
        DFS(x, y + 1, step + 1);
        vis[x][y + 1] = 0;
    }
}

/****************************>>>>HEADFILES<<<<****************************/
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
/****************************>>>>>DEFINE<<<<<*****************************/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define FIN             freopen("input.txt","r",stdin)
#define FOUT            freopen("output.txt","w",stdout)
#define CASE(T)         for(scanf("%d",&T);T--;)
typedef __int64 LL;
/****************************>>>>SEPARATOR<<<<****************************/
//测试数据
int ans[] = {0,3,7,17,41,99,239,577,1393,3363,8119,19601,47321,114243,275807,665857,1607521,3880899,9369319,22619537,54608393,131836323};
int N,T;
int main()
{
    //FIN;
    CASE(T)
    {
        scanf("%d",&N);
        printf("%d\n",ans[N]);
    }
    return 0;
}
通过比对数据,发现ans[i] = ans[i-1]*2 + ans[i-2]   ..... haha

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值