条形图(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 ...
随机推荐
- UVA 12083 POJ 2771 Guardian of Decency
/* http://acm.hust.edu.cn/vjudge/contest/view.action?cid=71805#problem/C */ 性质: [1]二分图最大点独立数=顶点数-二分图 ...
- Redhat_AS5下安装MySQL5.0总结
一.引言 使用Linux也有几年时间了,由于公司要做radius服务器用用到MySQL.从网上找了些资料. 二.安装Mysql 1.下载MySQL的安装文件 安装MySQL需要下面两个文件: MySQ ...
- ssh proxy配置
在.ssh目录下新建config文件,并添加以下内容: Host 10.100.101.123 ProxyCommand=nc -X 5 -x [proxyip:proxyport] %h %p
- shell脚本中$
变量名只能包含数字.字母和下划线,因为某些包含其他字符的变量有特殊含义,这样的变量被称为特殊变量. 例如,$ 表示当前Shell进程的ID,即pid ./package/kernel/mac80211 ...
- how to increase an regular array length in java?
Arrays in Java are of fixed size that is specified when they are declared. To increase the size of t ...
- regular expression tutorial
\d represent any number \D represents everything but a number \s represents any space \S Anything bu ...
- ios中的关键词retain release
内存分析 在函数中只要用new alloc copy 这样的分配空间时 则计算器retain就要为一 每调用一次就要加一 在.m文件中引用手动计数时 一定要调用[super dealloc]这 ...
- mvc页面中,显示自定义时间格式
1.在model中,遇到datetime格式的字段,用string来表示 model中 /// <summary> /// 开始时间 /// </summary> [Displ ...
- js实现td排序及分组分类
如题 <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...
- 实现jsp页面显示用户登录信息,利用session保存。
这是后台代码 这是jsp代码,上面是声明,下面是获得值.