2017广东工业大学程序设计竞赛决赛C.Collection Game(dp)

C.Collection Game
Time Limit: 1000 MSMemory Limit: 128000 K
Total Submit: 841(248 users)Total Accepted: 236(165 users)Special Judge: No
Description
POI and POJ are pair of sisters, one is a master in “Kantai Collection”, another is an excellent competitor in ACM programming competition. One day, POI wants to visit POJ, and the pace that between their homes is made of square bricks. We can hypothesis that POI’s house is located in the NO.1 brick and POJ’s house is located in the NO.n brick. For POI, there are three ways she can choose to move in every step, go ahead one or two or three bricks. But some bricks are broken that couldn’t be touched. So, how many ways can POI arrive at POJ’s house?

Input

There are multiple cases.

In each case, the first line contains two integers N(1<=N<=10000) and M (1<=M<=100), respectively represent the sum of bricks, and broke bricks. Then, there are M number in the next line, the K-th number a[k](2<=a[k]<=n-1) means the brick at position a[k] was broke.

Output
Please output your answer P after mod 10007 because there are too many ways.
Sample Input

5 1

3

Sample Output
3

所有点都能走的情况是一个变形的斐波那契数列f[i]=f[i-1]+f[i-2]+f[i-3],标记一下不能走的点,让其值为0,从而后面递推出的值都没有了从该点推出的值,即走过这点的所有情况都被排除
#include <iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#include<algorithm>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define maxn 100000+5
using namespace std;
ll f[10005],vis[10005];
int main()
{
    ll n,m,x;
    while(~scanf("%lld%lld",&n,&m))
    {
        mem(vis,0);
        for(int i=1;i<=m;i++)
        {
            scanf("%lld",&x);
            vis[x]=1;
        }
        f[1]=1;
        if(!vis[2])f[2]=1;
        if(!vis[3])f[3]=f[2]+1;
        for(int i=4;i<=n;i++)
        {
            if(!vis[i])
            f[i]=(f[i-1]+f[i-2]+f[i-3])%10007;
            else
            f[i]=0;
        }
        printf("%lld\n",f[n]);
    }
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值