Collection Game
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 ak 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
题意:
爬楼梯,期中第X阶梯坏了,不能爬,问爬N多少种方法
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
int flag[1111];
int dp[1111];
int x;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(flag,0,sizeof(flag));
memset(dp,0,sizeof(dp));
for(int i=0;i<m;i++)
{
scanf("%d",&x);
flag[x]=1;
}
dp[1]=1;
if(flag[2]==0)
dp[2]=1;
if(flag[3]==0)
dp[3]=dp[2]+1;
for(int i=4;i<=n;i++)
{
if(flag[i])
dp[i]=0;
else
dp[i]=(dp[i-1]+dp[i-2]+dp[i-3])%10007;
}
printf("%d\n",dp[n]%10007);
}
}
本文探讨了一个经典的爬楼梯问题变种,在这个问题中,部分楼梯损坏不可通行,需要计算从起点到达终点的不同路径数量。通过使用动态规划的方法,文章提供了一个有效的解决方案,并考虑到路径中损坏的楼梯,最终输出答案模10007的结果。
1594

被折叠的 条评论
为什么被折叠?



