Collection Game
Time Limit: 1000 MS Memory Limit: 128000 K
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.
OutputPlease output your answer P after mod 10007 because there are too many ways.
Sample Input
5 1
3
Sample Output3
题解:题意大概为n块砖,你在1的位置,走到n。你可以一次走一块或者两块,或者三块。但其中有些砖块是坏的,需要跳过,问你有几种走法……
大斐波那契……
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<string>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#define INF 0x3f3f3f3f
#define ll long long
#define For(i,a,b) for(int i=a;i<b;i++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
ll y[1100000];
map<ll,ll>q;
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
q.clear();
mem(y,0);
q[0]=q[1]=0;
y[3]=1;
ll a;
For(i,1,m+1)
{
scanf("%lld",&a);
q[a+2]=1;
}
For(i,4,n+5)
{
if(q[i]==0)
y[i]=(y[i-1]+y[i-2]+y[i-3])%10007;
}
ll k=y[n+2]%10007;
printf("%lld\n",k%10007);
}
}