"尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 C.Collection Game(DP)
2017-04-02 14:59
330 查看
题目:
思路:
比赛的时候考虑的不周全,没有特判,其实就是一个菲波那切数列,哪几个点不能走就把哪几个点标记一下,然后在递推的时候判断一下就好。
代码:
#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define N 20000+20
#define mod 10007
#define M 1000000+10
#define LL long long
using namespace std;
LL x,n,m;
LL num[10020];
bool flag[10020];
int main()
{
while(~scanf("%lld%lld",&n,&m))
{
mem(flag,0);
mem(num,0);
for(LL i=0; i<m; i++)
{
scanf("%lld",&x);
flag[x]=1;
}
num[1]=1;
if(!flag[2]) num[2]=1;
if(!flag[3]) num[3]=num[2]+1;
for(LL i=4; i<=n; i++)
{
if(flag[i])
num[i]=0;
else
num[i]=(num[i-1]+num[i-2]+num[i-3])%mod;
}
printf("%lld\n",num
);
}
return 0;
}
C.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, 4000 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 |
Submit | Message |
比赛的时候考虑的不周全,没有特判,其实就是一个菲波那切数列,哪几个点不能走就把哪几个点标记一下,然后在递推的时候判断一下就好。
代码:
#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define N 20000+20
#define mod 10007
#define M 1000000+10
#define LL long long
using namespace std;
LL x,n,m;
LL num[10020];
bool flag[10020];
int main()
{
while(~scanf("%lld%lld",&n,&m))
{
mem(flag,0);
mem(num,0);
for(LL i=0; i<m; i++)
{
scanf("%lld",&x);
flag[x]=1;
}
num[1]=1;
if(!flag[2]) num[2]=1;
if(!flag[3]) num[3]=num[2]+1;
for(LL i=4; i<=n; i++)
{
if(flag[i])
num[i]=0;
else
num[i]=(num[i-1]+num[i-2]+num[i-3])%mod;
}
printf("%lld\n",num
);
}
return 0;
}
相关文章推荐
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 C.Collection Game【递推】
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛——Hrbust2327 Collection Game
- HRBUST 2327 Collection Game "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 B.Blind Father(贪心)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛——Hrbust2326 Blind Father
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛D--Distinct Package Manager
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 D 2328 Distinct Package Manager
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 F.Final Ugly English(字符串处理)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 B Blind Father(单调栈)+G Great Atm(二进制)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- 20170402"尚学堂杯"哈尔滨理工大学第七届程序设计竞赛ABCDFG题解
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 B.Blind Father【思维枚举】
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 G(2331) Great Atm(二进制)(思路)