机器人塔

X星球的机器人表演拉拉队有两种服装,A和B。
他们这次表演的是搭机器人塔。

类似:

A
B B
A B A
A A B B
B B B A B
A B A B B A

队内的组塔规则是:

A 只能站在 AA 或 BB 的肩上。
B 只能站在 AB 或 BA 的肩上。

你的任务是帮助拉拉队计算一下,在给定A与B的人数时,可以组成多少种花样的塔。

输入一行两个整数 M 和 N,空格分开(0<M,N<500),分别表示A、B的人数,保证人数合理性。

要求输出一个整数,表示可以产生的花样种数。

例如:
用户输入:
1 2

程序应该输出:
3

再例如:
用户输入:
3 3

程序应该输出:
4


题目思路:

  搜索,先枚举最后一层,然后逐层往上迭代,看是否AB够用,够用则ans++。

  如下代码大概能水一些小数据吧——

  (1、把正三角形,改成了等腰直角三角形,更便于遍历;2、先计算出层数,然后底层确定后上面必定是唯一的局面,全部遍历判断即可!)

 #include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include<math.h>
#include <string.h>
#include<set>
using namespace std;
#define inf 0x3f3f3f3f
#define maxn 10000000
const double pi=acos(-1.0);
#define ll long long
#define N 108
using namespace std;
double fact(double a,double b,double c){
double y=sqrt(-*a*c);
double s=(-b+y)/2.0;
return s;
}
ll ans=;
int a[N][N];
int flag;
void build(int step,int anum,int bnum,int mstep){
if(anum<||bnum<){
return ;
}
if(step==-){
flag=;return ;
}
for(int i=;i<=step;i++){
if(a[step+][i]==a[step+][i+] ){
a[step][i]=;anum--;
}
else a[step][i]=,bnum--;
}
build(step-,anum,bnum,mstep); return ;
}
void dfs(int step,int pos,int anum,int bnum,int mstep){//枚举step行的存储数据,然后往上搭建看看
if(anum<||bnum<){
return ;
}
if(pos==step+){
flag=;
build(step-,anum,bnum,mstep);//按照最后一行进行搭建
ans+=flag;
return ;
}
for(int i=;i<=;i++){
a[step][pos]=i;
if(i==)
dfs(step,pos+,anum,bnum-,mstep);
else
dfs(step,pos+,anum-,bnum,mstep);
}
}
int main(){
int m,n;//分别表示A、B的人数
while(scanf("%d%d",&m,&n)!=EOF){
int x=(int)fact(1.0,1.0,-2.0*(m+n));//表示层数
printf("总行数=%d\n",x);
ans=;
memset(a,-,sizeof(a));
dfs(x,,m,n,x);
printf("%lld\n",ans);
} return ;
}

最新文章

  1. Linux环境下安装Tigase XMPP Server
  2. JS MD5
  3. 使用MiniProfiler调试ASP.NET MVC网站性能
  4. XML基础概念
  5. 淺析LED、LED背光、OLED的技術原理與區別
  6. 大型票务系统中username和password的安全性问题
  7. iOS 点转成字符串,再字符串转换成点
  8. java中Executor、ExecutorService、ThreadPoolExecutor介绍(转)
  9. mysql各种引擎对比、实战
  10. Java 有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?
  11. Date——时间戳转化为YYYY-MM-DD h:m:s时间格式
  12. Windows 系统里面的 hosts 文件
  13. android studio build.gradle 中的dependencies 的 compile jar文件
  14. listView悬浮头部的简单实现
  15. java基础-基本的输入与输出
  16. linux学习记录.4.常用命令
  17. Spring cloud 分布式锁
  18. java对象转json对象
  19. FJWC2019 最短路
  20. jquery监控input输入框的变化

热门文章

  1. ajax页面刷新小错误(提交按钮type必须为button,而不能是submit)
  2. Andrew Ng机器学习课程7
  3. Django 高级视图
  4. [转帖]AMD:Zen 2霄龙处理器每美元性能可达英特尔至强5.6倍
  5. Java之——实现微信小程序加密数据解密算法
  6. oracle 常用sql 经典sql函数使用 sql语法
  7. Zuul【基础配置】
  8. (零)linux 学习 -- 从 shell 开始
  9. C++ 获取系统当前时间(日历时)
  10. FZU2018级算法第三次作业 3.16 station