2017广东工业大学程序设计竞赛决赛C.Collection Game(dp)
来源:互联网 发布:淘宝卖家联系淘小二 编辑:程序博客网 时间:2024/06/14 02:49
C.Collection GameTime Limit: 1000 MSMemory Limit: 128000 KTotal Submit: 841(248 users)Total Accepted: 236(165 users)Special Judge: NoDescriptionPOI 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 Input5 1
3
Sample Output3所有点都能走的情况是一个变形的斐波那契数列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+5using 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 0
- 2017广东工业大学程序设计竞赛决赛C.Collection Game(dp)
- 2017广东工业大学程序设计竞赛决赛 C 爬楼梯
- 2017广东工业大学程序设计竞赛决赛:G. 等凹数字(数位DP)
- 2017广东工业大学程序设计竞赛决赛总结
- 2017广东工业大学程序设计竞赛决赛 网络赛
- 2017广东工业大学程序设计竞赛决赛 C题 爬楼梯(简单递推)
- 2017广东工业大学程序设计竞赛决赛 A 两只老虎
- 2017广东工业大学程序设计竞赛决赛【解题报告】[补完√]
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 C.Collection Game(DP)
- 2017广东工业大学程序设计竞赛决赛 D 只有通过毁灭才能揭示真理
- 2017广东工业大学程序设计竞赛 E倒水(Water)
- 哈尔滨理工大学第七届程序设计竞赛决赛(网络赛-高年级组)-C:小明打联盟(DP+思维)
- 【哈尔滨理工大学第七届程序设计竞赛决赛】 C 小明打联盟【DP +背包】
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 C.Collection Game【递推】
- 哈尔滨理工大学第七届程序设计竞赛决赛(网络赛-高年级组)B 幸运大奖【DP】
- 2017年第0届浙江工业大学之江学院程序设计竞赛决赛 Problem C: 勤劳的ACgirls (隔板问题)
- 2017年第0届浙江工业大学之江学院程序设计竞赛决赛—C(隔板法)
- 广东工业大学2017新生赛(决赛)-网络同步赛
- linux系统中从网络自动获取软件及更新的工具
- kubernetes源码阅读之controller-manager(二)
- JVM之GC详解
- Lintcode 二叉查找树中搜索区间
- 时间管理
- 2017广东工业大学程序设计竞赛决赛C.Collection Game(dp)
- A bug of user switch funtion in Android5 and its fix in Android7
- 使用CodeBlock编译一个C++程序
- CocosCreator热更新1.4.0
- 深度学习的浪潮已经开始!
- 一步一步写web之react实战(二)
- 【并查集】亲戚
- ios开发之NSNumber
- POJ 2014 Flow Layout G++