"尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 C.Collection Game【递推】
2017-04-03 13:34
387 查看
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 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 | ||||||
"尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 |
一共给你N个台阶,每次可以走1步,2步,3步,但是有m个台阶不能走,问走到n号台阶有多少种方法。
思路:
dp【i】=dp【i-1】+dp【i-2】+dp【i-3】;
if(位子i是不能走的)continue掉就可以了;
Ac代码:
#include<stdio.h> #include<string.h> using namespace std; #define mod 10007 int dp[10050]; int vis[10050]; int main() { int n,m; while(~scanf("%d%d",&n,&m)) { memset(vis,0,sizeof(vis)); memset(dp,0,sizeof(dp)); while(m--) { int x;scanf("%d",&x); vis[x]=1; } dp[1]=1; for(int i=2;i<=n;i++) { if(vis[i]==1)continue; if(i-1>=0)dp[i]+=dp[i-1]; if(i-2>=0)dp[i]+=dp[i-2]; if(i-3>=0)dp[i]+=dp[i-3]; dp[i]%=mod; } printf("%d\n",dp ); } }
相关文章推荐
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛——Hrbust2327 Collection Game
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 C.Collection Game(DP)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 B Blind Father(单调栈)+G Great Atm(二进制)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 hrbust 2331 Great Atm
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 B.Blind Father【思维枚举】
- HRBUST 2326 Blind Father "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛D--Distinct Package Manager
- HRBUST 2327 Collection Game "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- 20170402"尚学堂杯"哈尔滨理工大学第七届程序设计竞赛ABCDFG题解
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛——Hrbust2326 Blind Father
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)