hdu 5937 -- Equation(搜索)
problem description
Now little Ruins is puzzled by those bricks because he wants to put those bricks into as many different addition equations form x+y=zx+y=z as possible. Each brick can be used at most once and x, y, z are one digit integer.
As Ruins is a beginer of addition operation, xx, yy and zz will be single digit number.
Two addition equations are different if any number of xx, yy and zz is different.
Please help little Ruins to calculate the maximum number of different addition equations.
Input
First line contains an integer TT, which indicates the number of test cases.
Every test case contains one line with nine integers, the ithith integer indicates the number of bricks of ii.
Limits
1≤T≤30
0≤bricks number of each type≤100
Output
For every test case, you should output 'Case #x: y', where x indicates the case number and counts from 1 and y is the result.
Sample Input
3
1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2
0 3 3 0 3 0 0 0 0
Sample Output
Case #1: 2
Case #2: 6
Case #3: 2 题意:输入c[1]~c[9]分别表示1~9这些数字的个数,现在用这些数字构成等式x+y=z(x,y,z都是个位的数字),等式不能相同(1+2=3与2+1=3不同),求最多能都成多少个等式? 思路:先用结构体数组存储所用的等式,共36个,然后搜索就行。注意剪枝; 代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int ans;
int c[];
struct Node
{
int x,y,z;
}a[]; void init()
{
int tot=;
for(int i=;i<=;i++)
{
for(int j=;i+j<=;j++)
{
a[tot].x=i;
a[tot].y=j;
a[tot].z=i+j;
tot++;
}
}
} void dfs(int i,int sum)
{
if(i>=) { ans=max(ans,sum); return ; }
if(sum+-i+<=ans) return ;
int x=a[i].x;
int y=a[i].y;
int z=a[i].z;
if(c[x]>&&c[y]>&&c[z]>)
{
c[x]--; c[y]--; c[z]--;
if(c[x]>=&&c[y]>=&&c[z]>=) dfs(i+,sum+);
c[x]++; c[y]++; c[z]++;
}
dfs(i+,sum);
} int main()
{
init();
int T,Case=; cin>>T;
while(T--)
{
for(int i=;i<=;i++) scanf("%d",&c[i]);
ans=;
dfs(,);
printf("Case #%d: %d\n",Case++,ans);
}
return ;
}
hdu 5937 -- Equation(搜索)的更多相关文章
- HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))
Equation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 5937 Equation
题意: 有1~9数字各有a1, a2, -, a9个, 有无穷多的+和=. 问只用这些数字, 最多能组成多少个不同的等式x+y=z, 其中x,y,z∈[1,9]. 等式中只要有一个数字不一样 就是不一 ...
- HDU 5937 Equation(DFS+剪枝)
题目链接 Equation 给定1-9这9个数字各自的卡片数,求能构成形如$i + j = k$的等式个数 等式中$i,j,k$必须都为个位数 若两个等式中$i,j,k$不完全相等,则这两个等式为不同 ...
- hdu 5468(莫比乌斯+搜索)
hdu 5468 Puzzled Elena /*快速通道*/ Sample Input 5 1 2 1 3 2 4 2 5 6 2 3 4 5 Sample Output Case #1: ...
- HDU 4499.Cannon 搜索
Cannon Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Subm ...
- HDU 6627 equation (分类讨论)
2019 杭电多校 5 1004 题目链接:HDU 6627 比赛链接:2019 Multi-University Training Contest 5 Problem Description You ...
- HDU 1045 (DFS搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1045 题目大意:在不是X的地方放O,所有O在没有隔板情况下不能对视(横行和数列),问最多可以放多少个 ...
- HDU 1180 (BFS搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1180 题目大意:迷宫中有一堆楼梯,楼梯横竖变化.这些楼梯在奇数时间会变成相反状态,通过楼梯会顺便到达 ...
- HDU 2531 (BFS搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2531 题目大意: 你的身体占据多个点.每次移动全部的点,不能撞到障碍点,问撞到目标点块(多个点)的最 ...
随机推荐
- 使用Coding.net+Hexo+node.js+git来搭建个人博客
使用Coding.net来搭建基于Hexo的博客 一.准备工作 什么是Coding.net Coding可以说,就是国产的Github,但是,有一个功能使它似乎超越了GitHub-那就是 Web ID ...
- node.js后台快速搭建在阿里云(二)(pm2和nginx篇)
前期准备 阿里云服务器 node.js pm2 express nginx linux(推荐教程:鸟哥的私房菜) 简介 嗯……我只是个前端而已 在第一部分说完了express篇. 后面继续项目的部署, ...
- 扩展GridView实现无数据处理
提出需求 GridView控件在开发后台管理的时候非常方便快速,但是要实现没有数据时显示“没有数据”,并居中,是一件比较麻烦的事情,这里在一个公开的方法里实现了绑定List<T>和Data ...
- NSA武器库知识整理
美国国家安全局(NSA)旗下的"方程式黑客组织"(shadow brokers)使用的部分网络武器被公开,其中包括可以远程攻破全球约70%Windows机器的漏洞利用工具. 其中, ...
- chrome开发工具指南(三)
Security 面板 使用 Security Overview 可以立即查看当前页面是否安全. 检查各个源以查看连接和证书详情(安全源)或找出具体哪些请求未受保护(非安全源). Security O ...
- ios 初体验<真机调试>
1.很多小伙伴,初学ios后面,都想迫不及待的连接上真机,在真机上调试,本人今天花了许久时间,在网上查了许多资料,一直出现了个问题导致我没法真机调试, 问题一:Your session has exp ...
- IBM与麻省理工学院联合建立AI实验室 承诺投资2.4亿美元
IBM和麻省理工学院将通过今天宣布的一个新的联合实验室共同努力,对人工智能进行广泛的研究.麻省理工学院IBM沃森AI实验室将重点关注四个研究支柱:开发AI算法,使用物理学来创建AI计算的新硬 ...
- my new day in CNblog
感谢大家 今天正式在博客园平台开启我的第三个技术面博客 之前一直坚持在csdn平台撰文(http://blog.csdn.net/github_38885296)欢迎参观:) 因为觉得博客园知名度虽不 ...
- jQuery高级Ajax
.load();加载远程的HTML文件代码,并插入到指定的DOM节点中.可以只传入一个参数,表示加载一个静态的HTML代码片段. $("#div1").load("loa ...
- Java中equals和==之间的区别
今天在写表达式求值的时候,发现了equals和==||!=和!equals()之间是不一样的. 我就从网上搜了搜关于这方面的知识,然后在下面做一个总结: Java中有两类数据类型: 基本数据类型(Pr ...