HDU 2154:跳舞毯
跳舞毯
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7378 Accepted Submission(s): 3312
小黑买来一块圆形的毯子,把它们分成三等分,分别标上A,B,C,称之为“跳舞毯”,他的运动方式是每次都从A开始跳,每次都可以任意跳到其他块,但最后必须跳回A,且不能原地跳.为达到减肥效果,小黑每天都会坚持跳n次,有天他突然想知道当他跳n次时共几种跳法,结果想了好几天没想出来-_-
现在就请你帮帮他,算出总共有多少跳法。
当n为0时输入结束。
3
4
0
2
6
思路:利用递推,如果第n-2次在A上,则第n-2次到底n次,跳回A点有两种方法(A-B-C-A或A-C-B-A)。如果不在,则要使第n-1次不在A上,即跳的位置是唯一的。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define ll long long
#define INF 0x3f3f3f3f
const int maxn=1e4;
int a[maxn];
int main(int argc, char const *argv[])
{
int n;
a[1]=0;
a[2]=2;
a[3]=2;
for(int i=4;i<maxn;i++)
{
a[i]=(a[i-1]+2*(a[i-2]))%maxn;
}
while(~scanf("%d",&n)&&n)
{
printf("%d\n",a[n]);
}
return 0;
}
HDU 2154:跳舞毯的更多相关文章
- HDU 2154 跳舞毯
http://acm.hdu.edu.cn/showproblem.php?pid=2154 Problem Description 由于长期缺乏运动,小黑发现自己的身材臃肿了许多,于是他想健身,更准 ...
- HDU 2154 跳舞毯 | DP | 递推 | 规律
Description 由于长期缺乏运动,小黑发现自己的身材臃肿了许多,于是他想健身,更准确地说是减肥. 小黑买来一块圆形的毯子,把它们分成三等分,分别标上A,B,C,称之为“跳舞毯”,他的运动方式是 ...
- hdu 2154 跳舞毯(简单DP)
题意: 有一个圆圆的毯,被平均分成三个扇形.分为标记为A,B,C. 小余从A开始跳,每次可跳到相邻的扇形上.(A->B 或 A->C) 问小余跳n次,最后回到扇形A的方案数是多少. 思路: ...
- HDU - 2154 线性dp
思路:0表示A,1表示B,2表示C,d(i, j)表示在第j次时正好到达i. AC代码 #include <cstdio> #include <cmath> #include ...
- hdu acm 2154(多解取一解)
//题目中结果有一条限制就是最后必须跳回A,如果我们的思想框在这个条件上就很容易卡住,因为这样的条件下的路径很难有规律的罗列,然而我们说这个图形中有三个区域,我们算出每个区域的第n-1次的种类数,然后 ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- HDU 1385 Minimum Transport Cost (Dijstra 最短路)
Minimum Transport Cost http://acm.hdu.edu.cn/showproblem.php?pid=1385 Problem Description These are ...
- [转] HDU 题目分类
转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...
- HDU ACM 题目分类
模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...
随机推荐
- 4.4 Routing -- Specifying A Route's Model
一.概述 应用程序中,templates被models支持.但是templates是如何知道它们应该显示哪个model呢? 例如,你有一个photos模板,它是如何知道它该呈现哪个model呢? 这就 ...
- kindle 应用程序出错,无法启动选定的应用程序,请重试。问题排查过程及处理方案。
最近一段时间在使用Kindle商城时总是会出现“应用程序出错,无法启动选定的应用程序,请重试.” 对此我花了大约一小时的时间进行测试验证并与客服人员沟通,将过程记录如下,供出现同样问题的朋友们参考. ...
- Educational Codeforces Round 56 Solution
A. Dice Rolling 签到. #include <bits/stdc++.h> using namespace std; int t, n; int main() { scanf ...
- hdu5107 线段树
hdu 5107 这题说的是给了一个二维的 平面, 平面内有30000个点每个点都有自己的高度,然后又30000次的查询,每次查询给的是(X,Y,K), 要求出set(x,y){x,y|x<=X ...
- springcloud17---zuul-reg-exp
package com.itmuch.cloud; import org.springframework.boot.SpringApplication; import org.springframew ...
- Win10下安装Go开发环境
关于Go语言有多么值得学习,这里就不做介绍了,既然看了这篇文章,想必是对有学习意向. 这里是在Windows下安装Go环境,去中文社区的下载栏目,https://studygolang.com/dl ...
- oracle数据库中导入Excel表格中的数据
1.点击[工具]-->[ODBC 导入器],如图: 2.在导入器里选择第一个[来自ODBC的数据],用户名/系统DSN-->填写[Excel Files],输入用户名和密码,点击 [连接] ...
- c++语言中的遍历
原文地址:http://www.cnblogs.com/xylc/p/3653036.html 随着C++11标准的出现,C++标准添加了许多有用的特性,C++代码的写法也有比较多的变化. vecto ...
- artTemplate 模板使用
下载github中文件,浏览器引用lib/template-web.js 模板html: {{each ProductInfoList as prd}} <div class="res ...
- Educational Codeforces Round 47 D
Let's call an undirected graph $G=(V,E)$ relatively prime if and only if for each edge $(v,u)∈E$ $GC ...