首页 技术 正文
技术 2022年11月12日
0 收藏 352 点赞 4,138 浏览 1134 个字

The mook jong

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 226    Accepted Submission(s): 167

Problem Description![](../../data/images/C613-1001-1.jpg)

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).

 InputThere ar multiply cases. For each case, there is a single integer n( 1 < = n < = 60) OutputPrint the ways in a single line for each case. Sample Input123456 Sample Output1235812  题目大意:在由1*1的地砖铺成的1*n的院子里摆放木桩,每个木桩放在一个地板上。每两个木桩之间间隔至少两个地板,问有多少种放法。 解题思路:比赛的时候用的搜索,那叫一个慢,就打了40——60之间的表,算是蒙混过关。但是其实正解是dp。对于某个地板,可以放或者不放,那么如果放的话,结果加上dp[i-3]。如果不放的话,dp[i-1]是最优子结构,同时加上一共只放一个木桩在i位置的情况。dp[i]=dp[i-3]+dp[i-1]+1。结果超int需注意。 

#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
INT dp[65];
int main(){
dp[1]=1,dp[2]=2,dp[3]=3;
for(int i=4;i<=62;i++)
dp[i]=dp[i-3]+dp[i-1]+1;
int n;
while(scanf("%d",&n)!=EOF){
printf("%lld\n",dp[n]);
}
return 0;
}

  

 

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844