问题 K: WaWa的难题
问题 K: WaWa的难题
时间限制: 1 Sec 内存限制: 128 MB
提交: 570 解决: 125
[提交] [状态] [命题人:jsu_admin]
题目描述
今天HaHa在书上看到一个排列组合题目,思考很久后,仍然找不出其中的规律。
于是他把题目叙述给了WaWa。
题目:
————————————————————————
一个长度为N的排列,由数字1~N组成,它满足两个条件。
1、数字1永远在第一位。
2、任意两个相邻数字之差小于等于2。
现在给出一个N,
你能知道能组成多少个符合条件的排列吗?。
例如:
N=4
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
所以答案为4
————————————————————————
WaWa听后也是一脸懵逼。
现在WaWa想求助于你们,WaWa给出一个正整数N,问你用1~N能组成多少个符合题意的排列。
输入
每组数据输入一个正整数N(1<=N<=100)。
输出
样例输入 Copy
2
4
样例输出 Copy
1
4
dfs 打表前 10 项即可发现规律
a[i]=a[i-1]+a[i-3]+1
#include<stdio.h>
int num = ;
int sum = ;
void dfs(int n,int a){
if(sum == n)
{
num ++;
return ;
}
dfs(n,a++); }
int main()
{
int n;
long long a[];
a[]=;
a[]=;
a[]=;
a[]=;
for(int i=;i<=;i++)
a[i]=a[i-]+a[i-]+;
while(scanf("%d",&n)!=EOF)
{
// num = 0;
// dfs(n,1);
printf("%lld\n",a[n]);
}
}
打表
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=;
const int MOD=1e9+;
const double PI = acos(-1.0);
const double EXP = 1E-;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int ans=;
int vis[];
void dfs(int x,int c){
if(c>=n){
ans++;
return;
}
int l=max(,x-);
int r=min(n,x+);
for(int i=l;i<=r;i++){
if(!vis[i]){
vis[i]=;
dfs(i,c+);
vis[i]=;
}
}
}
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
ll a[N];
a[]=;
a[]=;
a[]=;
a[]=;
for(int i=;i<=;i++)
a[i]=a[i-]+a[i-]+;
while(~scanf("%d",&n)){
//ans=0;
//memset(vis,0,sizeof(vis));
//vis[1]=1;
//dfs(1,1);
cout << a[n] << endl;
}
//cout << "Hello world!" << endl;
return ;
}
问题 K: WaWa的难题的更多相关文章
- django模型操作
Django-Model操作数据库(增删改查.连表结构) 一.数据库操作 1.创建model表
- hduoj 1251 统计难题
http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory ...
- HDU 1251统计难题
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- hdu1251 统计难题
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=1251 题目: 统计难题 Time Limit: 4000/2000 MS (Java/Othe ...
- hdu 1251:统计难题(字典树,经典题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- 完全偶图K(3,3)与完全图K5是否存在平面表示
本文论述k(3, 3)与K5平面表示的存在性.首先给出图的平面表示的定义: 若可以在平面里画出一个图而让边没有任何交叉(边的交叉是指边的直线或弧线在它们的公共端点以外的地方相交),则这个图是平面性的. ...
- 双向广搜+hash+康托展开 codevs 1225 八数码难题
codevs 1225 八数码难题 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Yours和zero在研究A*启 ...
- HDU 1251 统计难题(Trie模版题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- nyist 673 悟空的难题
http://acm.nyist.net/JudgeOnline/problem.php?pid=673 悟空的难题 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 ...
随机推荐
- ESP8266-12F
读者可以把ESP8266当做Arduino+WiFi功能来开发 ESP8266模块支持STA/AP/STA+AP 三种工作模式: STA 模式:ESP8266模块通过路由器连接互联网,手机或电脑通过互 ...
- man clock
CLOCK(3) Linux程序员手册 CLOCK(3) 名称 时钟-确定处理器时间 简介 #include <time.h> clock_t clock(void); ...
- 【NOIP2015模拟11.3】IOIOI卡片占卜
题目 K理事长很喜欢占卜,经常用各种各样的方式进行占卜.今天,他准备使用正面写着"I",反面写着"O"的卡片为今年IOI的日本代表队占卜最终的成绩. 占卜的方法 ...
- SQL插入字段
//SQL插入字段 String dropTable="drop table if exists test;"; String columnGid ="alter tab ...
- echart--如何自定义提示框的内容和样式实例
图例的大概样子 具体设置代码为:
- 内联元素的盒子模型与文档流定位padding属性
内联元素的盒子模型 1.内联元素不能设置width宽度和高度height span{width:200px ; height:200px} 与 span{width:100 ...
- mysql UNIQUE约束 语法
mysql UNIQUE约束 语法 作用:UNIQUE 约束唯一标识数据库表中的每条记录. 江苏大理石平台 说明:UNIQUE 和 PRIMARY KEY 约束均为列或列集合提供了唯一性的保证.PRI ...
- Ubuntu 16.04下使用docker部署rabbitmq
(以下docker相关的命令,需要在root用户环境下或通过sudo提升权限来进行操作.) 1.拉取rabbimq镜像到本地 docker pull rabbitmq 2. Docker运行rabbi ...
- three arrays
three arrays 字典树上贪心 #include<bits/stdc++.h> using namespace std; ][][]; ][]; ]; ]; ][]; ][]; i ...
- [CSP-S模拟测试]:购物(柯朵莉树)
题目描述 $visit_world$有一个商店,商店里卖$N$个商品,第$i$个的价格为$a[i]$我们称一个正整数$K$是美妙的,当且仅当我们可以在商店里选购若干个商品,使得价格之和落在区间$[K, ...