ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

C-Hedwig's Ladder---2018纽约区域赛(递推)

2021-06-05 19:02:14  阅读:187  来源: 互联网

标签:set Hedwig Ladder number --- length data dp


Hedwig’s Ladder

题目链接http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2272
Time Limit: 1 Sec Memory Limit: 128 Mb

Description

Hedwig the hamster enjoys exploring networks of hamster tubes. Each day, Hedwig’s ownerrearranges the tubes to form a new network of tubes.

One day, Hedwig awoke to find that the network of tubes had been arranged in a ladder pattern as shown below, where each junction point (An and Bn) contained a small piece of carrot (Hedwig loves carrots!). Hedwig had not yet explored the new tube network and had no idea how long it was (it may go on forever!)

在这里插入图片描述
avatar

Hedwig decided to make a game where given a length, figure out how many paths from the start, A0, of the given length there are using these rules: Each time a junction is reached, Hedwig eats the piece of carrot that is there. A junction can only be used if there is a piece of carrot there when Hedwig arrives.

To help Hedwig out, you will write a program which finds the number of paths from A0 of a specified length which do not hit any junction more than once. For example, all the paths of length 3 are shown below:
在这里插入图片描述
avatar

Input

The first line of input contains a single decimal integer P, (1 ≤ P ≤ 800), which is the number of data sets that follow. Each data set should be processed identically and independently.

Each data set consists of one line of input. The line contains the data set number, K, followed by the length, N, (1 ≤ N ≤ 1000)of the paths to be counted.

Output

For each data set there is one line of output.

The output line consists of the data set number, K, followed by the number of paths of length N modulo 10007.

Sample Input

4
1 3
2 9
3 18
4 111

Sample Output

1 6
2 110
3 8361
4 237


题目大意:如图,给你一个无限长的地图,宽度只有1步,再给你你能走的步数,不能走走过的点,问你有多少种走法,当你能走三步时就像上图加粗的路线一样有6种走法。
emmmm。。。这题当时没什么想法,但dqa大佬找了个规律,然后A了。。。。
有时候比赛可能也就是这样吧,大胆假设,交它一发。。。
具体的规律是这样的,以dp[1]和dp[2]作为边界,接下来奇数的为dp[i-1]+dp[i-2]+1,偶数就不用加1了。。。预处理一下,然后交它一发。。。

#include <cstdio>
#define mod 10007
int dp[1200];
int main()
{
	int t,n,id; 
	dp[1]=2;dp[2]=3;
	for (int i=3; i<=1000; i++){
		if (i%2) dp[i]=(dp[i-1]+dp[i-2]+1)%mod;
		else dp[i]=(dp[i-1]+dp[i-2])%mod;
	}
	scanf ("%d",&t);
	for (int i=1; i<=t; i++){
		scanf ("%d%d",&id,&n);
		printf ("%d %d\n",i,dp[n]);
	}
	
	return 0;
}

标签:set,Hedwig,Ladder,number,---,length,data,dp
来源: https://blog.51cto.com/u_15249461/2870460

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有