条形图(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)的更多相关文章

  1. 利用Python进行数据分析(2) 尝试处理一份JSON数据并生成条形图

    一.JSON 数据准备 首先准备一份 JSON 数据,这份数据共有 3560 条内容,每条内容结构如下: 本示例主要是以 tz(timezone 时区) 这一字段的值,分析这份数据里时区的分布情况. ...

  2. EF:split your EDMX file into multiple diagrams

    我们可以把一个EDMX文件划分为多个类图: 1.在VS中打开EDMX设计器: 2.切换到“模型浏览器”属性设置窗口: 3.在diagrams上右键菜单中选择“添加新的关系图”: 4.在原来的关系图上可 ...

  3. How to generate UML Diagrams from Java code in Eclipse

    UML diagrams compliment inline documentation ( javadoc ) and allow to better explore / understand a ...

  4. 在Excel中制作金字塔条形图

    使用场景:一项市场调查研究中,男性和女性.赞同和反对.满意和不满意的两方面的消费者,他们在某些项目上的指标分布特性一项产品组合决策中,乐观场景和悲观场景下各产品的获利情况一个产品试销活动中,不同门店渠 ...

  5. matlab 绘制条形图

    Matlab使用bar和barh函数来绘制二维条形图.分别是绘制二维垂直条形图和二维水平条形图. 转自:http://jingyan.baidu.com/article/64d05a02524e63d ...

  6. codeforces Diagrams & Tableaux1 (状压DP)

    http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132 ...

  7. 最牛逼android上的图表库MpChart(三) 条形图

    最牛逼android上的图表库MpChart三 条形图 BarChart条形图介绍 BarChart条形图实例 BarChart效果 最牛逼android上的图表库MpChart(三) 条形图 最近工 ...

  8. (转) Deep learning architecture diagrams

    FastML Machine learning made easy RSS Home Contents Popular Links Backgrounds About Deep learning ar ...

  9. Class diagrams

    So far we have seen stack diagrams, which show the state of a program, and object diagrams, which sh ...

随机推荐

  1. A. Night at the Museum Round#376 (Div. 2)

    A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. A. Mike and Cellphone(Round 361 Div.2)

    写一半去开程序的时候不小心关了网页,LOFTER我都不奢望加入代码高亮,最起码我关闭的时候弹个对话框,再不济也给我定时保存一下草稿吧. A. Mike and Cellphone time limit ...

  3. 初次使用IntelliJ IDEA 2016.2

    换电脑的还有一个目的就是我准备采用新的IDE了 之前一直用的是myeclipse,但是现在准备尝试idea 这边做个记录,idea的破解参考下面这个网址:http://blog.csdn.net/u0 ...

  4. Ajax应用-定义一套自己的Ajax框架

    —————————————————————————— <script type="text/javascript">            //定义个一个functio ...

  5. java中的静态代码块等执行顺序

    http://www.cnblogs.com/naruto469/p/3608459.html public class Print { 2 3 public Print(String s){ 4 S ...

  6. mybatis 总结(1)

    注意事项 1.在使用type 和JavaType 以及reusltType ,ofType的时候一定要设置"别名"在mybatis.cfg.xml中设置 <typeAlias ...

  7. how to use the curses library in unix?

    In linux, you can use the ncurses library to use the terminal as a text buffer: move the cursor arou ...

  8. Adobe Flash CC 2014 下载及破解

    来源 :http://prodesigntools.com/adobe-cc-2014-direct-download-links.html 地址:http://trials3.adobe.com/A ...

  9. 设计一种前端数据延迟加载的jQuery插件(2)

    背景 最近看到很多网站都运用到了一种前端数据延迟加载技术,包括淘宝,新浪网等等,这样做的目的可以使得一些未显示的图片随 着滚动条的滚动进行延迟显示. 好处显而易见,可以减少前端对于图片的Http请求, ...

  10. 漫谈QML

    漫谈 QML/Qt Quick QML是从Qt 4.7开始引入的,QML是一种声明语言,使得可以像设计师思考的一样编码,并且Qt Quick元素就是应用程序的编译单元,每一帧的故事板被声明为元素树中的 ...