当前位置: 代码迷 >> 综合 >> HRBUST 2327 Collection Game 【简单DP】
  详细解决方案

HRBUST 2327 Collection Game 【简单DP】

热度:25   发布时间:2023-11-11 11:32:10.0

Collection Game

 
Time Limit: 1000 MS Memory Limit: 128000 K
Total Submit: 127(53 users) Total Accepted: 57(50 users) Rating: 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
Source
"尚学堂杯"哈尔滨理工大学第七届程序设计竞赛



POI到POJ的路是由多个街区组成的,POI想要去看望POJ,但POI到POJ的路上,有些街区因为损坏而无法行走。POI可以一次向前走一步两步或三步。问POI有多少种到达POJ的方法。



这题是一题动态规划。。

把不能走的街区标记为1,动态规划扫时跳过这些街区。


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;int dp[10005];///动态规划数组
int vis[10005];///记录访问情况const int MOD =10007;int main()
{int n,m;while(~scanf("%d %d",&n,&m)){memset(dp,0,sizeof(dp));memset(vis,0,sizeof(vis));int zb;for(int i=0; i<m; i++){scanf("%d",&zb);///不能走的标记为1vis[zb]=1;}dp[1]=1;///初始步数标记为1for(int i=1; i<=n; i++){if(vis[i])continue;if(i>=1)///递归大法好。。。!!!{dp[i]=dp[i]+dp[i-1];}if(i>=2){dp[i]=dp[i]+dp[i-2];}if(i>=3){dp[i]=dp[i]+dp[i-3];}dp[i]%=MOD;}printf("%d\n",dp[n]);}return 0;
}


  相关解决方案