条形图(diagrams)
条形图(diagrams)
题目描述
小 虎刚上了幼儿园,老师让他做一个家庭作业:首先画3行格子,第一行有3个格子,第二行有2个格子,第三行有3个格子。每行的格子从左到右可以放棋子,但要 求除第一行外,每行放的棋子数不能超过上一行的棋子数。玩了一会,小虎问哥哥大虎:这个作业有很多种摆放法,我想都找到,但我不知道有多少种方案,你能帮 助我吗?
大虎是学校信息学集训队的,立刻想到用计算机来解决这个问题,并很快有了解答:13。第2天,他把问题拿到学校,并说如果第一行有n个格子,第二行有n-1个格子,……,第n行有1个格子,怎么办?现在请你一块来帮助他解决这个难题。
输入
仅1行,一个正整数n。
30%数据:1≤n≤12;
50%数据:1≤n≤30;
100%数据:1≤n≤100。
输出
1行,方案总数。
样例输入
2
样例输出
4
提示
样例解释
四种摆法如下(*表示棋子_表示空格):
*_ *_ ** **
_ * _ *
分析:
dp[i][j]表示当第i行(i个格子)有j个棋子的总情况,则dp[i][j]=Σ(dp[i-1][0],dp[i-1][1]...dp[i-1][j/2]);
注意:最前面一行(第n行)必须放棋子;本题会爆long long,需要字符串处理;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <ext/rope>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=2e5+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m;
string dp[][],ans;
string work(string a,string b)
{
int len1=a.length(),len2=b.length(),ma=max(len1,len2),cnt=,i;
string now;
for(i=;i<ma;i++)
{
if(i<len1&&i<len2)
{
cnt=a[i]-''+b[i]-''+cnt;
now+=cnt%+'';
cnt=cnt/;
}
else if(i<len1)
{
cnt=a[i]-''+cnt;
now+=cnt%+'';
cnt=cnt/;
}
else if(i<len2)
{
cnt=b[i]-''+cnt;
now+=cnt%+'';
cnt=cnt/;
}
}
if(cnt)now+=cnt+'';
return now;
}
int main()
{
int i,j,k,t;
ans="";
dp[][]=dp[][]="";
for(int i=;i<=;i++)
for(int j=;j<=i;j++){
dp[i][j]="";
for(int k=;k<=j&&k<=i-;k++)
dp[i][j]=work(dp[i][j],dp[i-][k]);
}
scanf("%d",&n);
rep(i,,n)ans=work(ans,dp[n][i]);
reverse(ans.begin(),ans.end());
cout<<ans<<endl;
//system ("pause");
return ;
}
条形图(diagrams)的更多相关文章
- 利用Python进行数据分析(2) 尝试处理一份JSON数据并生成条形图
一.JSON 数据准备 首先准备一份 JSON 数据,这份数据共有 3560 条内容,每条内容结构如下: 本示例主要是以 tz(timezone 时区) 这一字段的值,分析这份数据里时区的分布情况. ...
- EF:split your EDMX file into multiple diagrams
我们可以把一个EDMX文件划分为多个类图: 1.在VS中打开EDMX设计器: 2.切换到“模型浏览器”属性设置窗口: 3.在diagrams上右键菜单中选择“添加新的关系图”: 4.在原来的关系图上可 ...
- How to generate UML Diagrams from Java code in Eclipse
UML diagrams compliment inline documentation ( javadoc ) and allow to better explore / understand a ...
- 在Excel中制作金字塔条形图
使用场景:一项市场调查研究中,男性和女性.赞同和反对.满意和不满意的两方面的消费者,他们在某些项目上的指标分布特性一项产品组合决策中,乐观场景和悲观场景下各产品的获利情况一个产品试销活动中,不同门店渠 ...
- matlab 绘制条形图
Matlab使用bar和barh函数来绘制二维条形图.分别是绘制二维垂直条形图和二维水平条形图. 转自:http://jingyan.baidu.com/article/64d05a02524e63d ...
- codeforces Diagrams & Tableaux1 (状压DP)
http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132 ...
- 最牛逼android上的图表库MpChart(三) 条形图
最牛逼android上的图表库MpChart三 条形图 BarChart条形图介绍 BarChart条形图实例 BarChart效果 最牛逼android上的图表库MpChart(三) 条形图 最近工 ...
- (转) Deep learning architecture diagrams
FastML Machine learning made easy RSS Home Contents Popular Links Backgrounds About Deep learning ar ...
- Class diagrams
So far we have seen stack diagrams, which show the state of a program, and object diagrams, which sh ...
随机推荐
- android CTS测试
CTS认证是获得Google推出的Android系统中Android Market服务的前提 CTS兼容性测试的主要目的和意义在于使得用户在Android系统的应用过程中,有更好的用户体验,并展现出A ...
- vbs鼠标方法——模拟鼠标按键
'*********************************************************************** ' 代码开始 '******************* ...
- QTP使用小技巧
1.创建action template. 当希望在每一个新建action时都增加一些头部说明,比如作者.创建日期.说明等,用action template 来实现最简单快捷. ...
- cPanel 安装方法
. 如何安装cPanel/WHM? 答:安装过程较长,建议使用screen或nohupscreen: yum -y install screen perl screen -S cpanel cd /h ...
- Chapter 1 First Sight——31
I took notes carefully anyway, always looking down. 不论怎么样我都仔细的记着笔记,一直低着头. I couldn't stop myself fro ...
- @Value 注解获取properties值
转自:使用Spring 3的@value简化配置文件的读取 Spring 3支持@value注解的方式获取properties文件中的配置值,大简化了读取配置文件的代码. 1.在application ...
- if语句,函数function
1.语句 一般分为顺序,分支和循环语句. if是分支语句 格式1:if(){} 若满足就进入花括号,若不满足就跳过 格式2:if(){}else(){}二选一.若if满足则else一定不执行,反之则 ...
- 二维 ST POJ 2019
题目大意:给你一个n*n的矩阵,每次给你一个点(x,y),以其为左上角,宽度为b的矩阵中最小的数值和最大数值的差是多少? 一共k个询问. 思路:简单的二维st. 定义dp(i,j,k,L)表示以(i ...
- wl18xx编译的时候出现WARNING: "simple_open" WARNING: "wl12xx_get_platform_data"
................................................................................................... ...
- Guess the Array
Guess the Array time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...