Problem Description

ZJiaQ want to become a strong man, so he decided to play the mook jong。ZJiaQ want to put some mook jongs in his backyard. His backyard consist of n bricks that is 1*1,so it is 1*n。ZJiaQ want to put a mook jong in a brick. because of the hands of the mook jong, the distance of two mook jongs should be equal or more than 2 bricks. Now ZJiaQ want to know how many ways can ZJiaQ put mook jongs legally(at least one mook jong).

Input

There ar multiply cases. For each case, there is a single integer n( 1 < = n < = 60)

Output

Print the ways in a single line for each case.

Sample Input

1

2

3

4

5

6

Sample Output

1

2

3

5

8

12

递推搞定。。。

官方解题:

令f[i]为最后一个木人桩摆放在i位置的方案,令s[i]为f[i]的前缀和。很容易就能想到f[i]=s[i-3]+1,s[i]=s[i-1]+f[i],而s[n]即是所求答案。本题唯一一个值得注意的点就是当n接近60时会爆int。

开始的时候纠结在每个n能放几个,从而分组(1,2,3,4…)结果怎么也找不出规律。

当时A的时候用的也是递推的方式,放下第一个在第一个位置,剩下的只能是在剩下的i-3个位置放(不用关心在这i-3个位置到底放了几个) = a[i-3];在第二个位置,再在剩下的i-4个位置放 = a[i-4] ,一次类推。

#include<cstdio>
#include<cmath>
#include<stdlib.h>
#include<map>
#include<set>
#include<time.h>
#include<vector>
#include<queue>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define rd(a) scanf("%d",&a)
#define rdLL(a) scanf("%I64d",&a)
#define rdd(a,b) scanf("%d%d",&a,&b)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define MOD 1000000007
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,1,sizeof(a))
typedef pair<int , int> P; int main()
{
LL a[100];
int n;
a[1]=1,a[2]=2,a[3]=3;
LL sum=1,coun=2;
for(int i = 4;i<61;i++)
a[i]=sum+i,sum+=a[coun++];
while( ~rd(n) ){
printf("%I64d\n",a[n]);
}
return 0;
}

BC之The mook jong的更多相关文章

  1. HDU5366 The mook jong (DP)

    The mook jong 问题描述 ZJiaQ为了强身健体,决定通过木人桩练习武术.ZJiaQ希望把木人桩摆在自家的那个由1*1的地砖铺成的1*n的院子里.由于ZJiaQ是个强迫症,所以他要把一个木 ...

  2. HDU5366——The mook jong——dp

    The mook jong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  3. HDU 5366:The mook jong 递推

    The mook jong  Accepts: 506  Submissions: 1281  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit ...

  4. DP BestCoder Round #50 (div.2) 1003 The mook jong

    题目传送门 /* DP:这题赤裸裸的dp,dp[i][1/0]表示第i块板放木桩和不放木桩的方案数.状态转移方程: dp[i][1] = dp[i-3][1] + dp[i-3][0] + 1; dp ...

  5. The mook jong

    The mook jong Accepts: 506 Submissions: 1281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...

  6. HDU 5366 The mook jong (简单DP)

    题意:ZJiaQ希望把木人桩摆在自家的那个由1*1的地砖铺成的1*n的院子里.由于ZJiaQ是个强迫症,所以他要把一个木人桩正好摆在一个地砖上,由于木人桩手比较长,所以两个木人桩之间地砖必须大于等于两 ...

  7. BestCoder Round #50 (div.1) 1003 The mook jong (HDU OJ 5366) 规律递推

    题目:Click here 题意:bestcoder 上面有中文题目 分析:令f[i]为最后一个木人桩摆放在i位置的方案,令s[i]为f[i]的前缀和.很容易就能想到f[i]=s[i-3]+1,s[i ...

  8. HDU 5366 The mook jong

    先暴力写了一个DFS,然后找规律.. #include<cstdio> #include<cstring> #include<cmath> #include< ...

  9. HDU 5366 dp 递推

    The mook jong Accepts: 506 Submissions: 1281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...

随机推荐

  1. JVM通过代理服务器连接网络的参数设置

    -DproxySet=true-Dhttp.proxyHost=your.proxy.net-Dhttp.proxyPort=8080

  2. DataList与Repeater嵌套绑定

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="home.aspx.cs&quo ...

  3. HDP2.4安装(三):MySql安装

    在安装Ambari时,Ambari默认的数据库是ProstgreSQL,对ProstgreSQL不太熟悉,选择使用MySql. 但Centos 7 默认支持的是MariaDB数据库. MariaDB是 ...

  4. scala中的=>符号的含义

    [声明]本帖的内容是copy来的,来源为stack overflow. It has several meanings in Scala, all related to its mathematica ...

  5. jsoncpp用法通俗易懂之将数据合成json格式

    void *upload(void *pParam) { CUpSender *s = (CUpSender*)pParam; map<string, string> mx; char t ...

  6. 通信原理读书笔记:常规AM调制的功率

    Proakis,通信系统原理,p101: 两个不同频率正弦和的功率为其功率的和. 计算功率时,和的平方展开后会出现两个正弦乘积项,按积化和差展开后在公共周期内积分为零.

  7. 【转】JVM 分代GC策略分析

    我们以Sun HotSpot VM来进行分析,首先应该知道,如果我们没有指定任何GC策略的时候,JVM默认使用的GC策略.Java虚拟机是按照分代的方式来回收垃圾空间,我们应该知道,垃圾回收主要是针对 ...

  8. 228. Summary Ranges

    Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...

  9. Apple dev travel

    Objective-C最基础语法之Class定义: http://mobile.51cto.com/iphone-281925.htm  Table View: http://www.appcoda. ...

  10. JAVA使用HBASE常用方法

    package HBaseTest; /** * Created by root on 11/11/22. */ import java.io.IOException; import org.apac ...