• [1028] 该减肥了

  • 时间限制: 1000 ms 内存限制: 65535 K
  • 问题描述
  • 由于长期缺乏运动,Teacher Xuan发现自己的身材臃肿了许多,于是他想健身,更准确地说是减肥。Teacher Xuan买来一块圆形的毯子,把它们分成三等分,分别标上A,B,C,称之为“跳舞毯”,他的运动方式是每次都从A开始跳,每次都可以任意跳到其他块,但最后必须跳回A,且不能原地跳.为达到减肥效果,Teacher Xuan每天都会坚持跳n次,有天他突然想知道当他跳n次时共几种跳法,结果想了好几天没想出来-_-。现在请你帮帮他,算出总共有多少跳法。

  • 输入
  • 测试输入包含若干测试用例。每个测试用例占一行,表示n的值(1<=n<=1000)。 
    当n为0时输入结束。
  • 输出
  • 每个测试用例的输出占一行,由于跳法非常多,输出其对10000取模的结果.
  • 样例输入
  • 2
    3
    4
    0
  • 样例输出
  • 2
    2
    6

题目链接:NBUT 1028

用dp[i][k]表示跳i下到第k种垫子的数量,显然一开始跳一下可以到B或C因此dp[1][B]=dp[1][C]=1,由于不能原地跳,dp[1][A]=0,然后就可以递推了,

代码中用enum方便理解

代码:

#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<string>
#include<deque>
#include<stack>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define INF 0x3f3f3f3f
#define CLR(x,y) memset(x,y,sizeof(x))
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
typedef pair<int,int> pii;
typedef long long LL;
const double PI=acos(-1.0);
const int N=1005;
const int mod=10000;
int dp[N][3];
enum {A,B,C};
void init()
{
CLR(dp,0);
dp[1][B]=1;
dp[1][C]=1;
}
int main(void)
{
int n,i,j,k;
init();
for (i=2; i<N; ++i)
{
dp[i][B]=(dp[i-1][A]+dp[i-1][C])%mod;
dp[i][C]=(dp[i-1][A]+dp[i-1][B])%mod;
dp[i][A]=(dp[i-1][B]+dp[i-1][C])%mod;
}
while (~scanf("%d",&n)&&n)
printf("%d\n",dp[n][A]);
return 0;
}

NBUT 1028 该减肥了(简单递推)的更多相关文章

  1. HDU 2085 核反应堆 --- 简单递推

    HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点 ...

  2. Flags-Ural1225简单递推

    Time limit: 1.0 second Memory limit: 64 MB On the Day of the Flag of Russia a shop-owner decided to ...

  3. 简单递推 HDU-2108

    要成为一个ACMer,就是要不断学习,不断刷题...最近写了一些递推,发现递推规律还是挺明显的,最简单的斐波那契函数(爬楼梯问题),这个大家应该都会,看一点稍微进阶了一点的,不是简单的v[i] = v ...

  4. UVA10943简单递推

    题意:      给你两个数字n,k,意思是用k个不大于n的数字组合(相加和)为n一共有多少种方法? 思路:       比较简单的递推题目,d[i][j]表示用了i个数字的和为j一共有多少种情况,则 ...

  5. 2018.06.29 NOIP模拟 1807(简单递推)

    1807 题目背景 SOURCE:NOIP2015-SHY-2 题目描述 给出一个由数字('0'-'9')构成的字符串.我们说一个子序列是好的,如果他的每一位都是 1.8.0.7 ,并且这四个数字按照 ...

  6. dp的简单递推笔记1

    (1)转自rockZ的博文 UVa 10328 - Coin Toss (递推) 题意:给你一个硬币,抛掷n次,问出现连续至少k个正面向上的情况有多少种. 原题中问出现连续至少k个H的情况,很难下手. ...

  7. POJ_2478 Farey Sequence 【欧拉函数+简单递推】

    一.题目 The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbe ...

  8. <每日一题> Day5:简单递推两题

    原题链接 参考代码: #include <iostream> using namespace std; typedef long long ll; + ; ll dp[maxn]; int ...

  9. hdu 5273 Dylans loves sequence 逆序数简单递推

    Dylans loves sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...

随机推荐

  1. fedora 添加其他操作系统到 GRUB 2 菜单

    # yum install os-prober # grub2-mkconfig -o /boot/grub2/grub.cfg

  2. Zabbix报告无交换内存主机 Lack of free swap space on xxxxx

    [root@xx ~]# free -m total used free shared buffers cached Mem: 3832 3488 343 0 267 2389 -/+ buffers ...

  3. DRF如何序列化外键的字段

    我觉得在有些应用场景下,这个操作是有用的,因为可以减少一个AJAX的请求,以增加性能. 当然,是二次请求,还是一次传输.这即要考虑用户体验,还要兼顾服务器性能. 一切是有条件的平衡吧.就算是一次传输, ...

  4. hdu 1312:Red and Black(DFS搜索,入门题)

    Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  5. JAVA学习:maven开发环境快速搭建

    转自:http://tech.it168.com/a2011/1204/1283/000001283307.shtml 最近,开发中要用到maven,所以对maven进行了简单的学习.因为有个mave ...

  6. codeforces Round #263(div2) D. Appleman and Tree 树形dp

    题意: 给出一棵树,每个节点都被标记了黑或白色,要求把这棵树的其中k条变切换,划分成k+1棵子树,每颗子树必须有1个黑色节点,求有多少种划分方法. 题解: 树形dp dp[x][0]表示是以x为根的树 ...

  7. POJ 1523 SPF tarjan求割点

                                                                   SPF Time Limit: 1000MS   Memory Limit ...

  8. Android Touch事件传递机制解析

    android系统中的每个ViewGroup的子类都具有下面三个和TouchEvent处理密切相关的方法: 1)public boolean dispatchTouchEvent(MotionEven ...

  9. linux中使用top获取进程的资源占用信息

    在linux中使用top获取进程的资源占用信息: Cpu(s):  1.0%us,  0.0%sy,  0.0%ni, 98.3%id,  0.7%wa,  0.0%hi,  0.0%si,  0.0 ...

  10. LinQ的一些基本语句

    LINQ(Language Integrated Query)即语言集成查询.它是一种语言特性和API,使得你可以使用统一的方式编写各种查询,查询的对象包括xml.对象集合.SqlServer数据库等 ...