hdu 5937 -- Equation(搜索)

时间:2022-09-18 20:48:10

题目链接

problem description

Little Ruins is a studious boy, recently he learned addition operation! He was rewarded some number bricks of 11 to 99 and infinity bricks of addition mark '+' and equal mark '='.

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(搜索)的更多相关文章

  1. HDU 5937 Equation 【DFS&plus;剪枝】 (2016年中国大学生程序设计竞赛(杭州))

    Equation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  2. HDU 5937 Equation

    题意: 有1~9数字各有a1, a2, -, a9个, 有无穷多的+和=. 问只用这些数字, 最多能组成多少个不同的等式x+y=z, 其中x,y,z∈[1,9]. 等式中只要有一个数字不一样 就是不一 ...

  3. HDU 5937 Equation(DFS&plus;剪枝)

    题目链接 Equation 给定1-9这9个数字各自的卡片数,求能构成形如$i + j = k$的等式个数 等式中$i,j,k$必须都为个位数 若两个等式中$i,j,k$不完全相等,则这两个等式为不同 ...

  4. hdu 5468&lpar;莫比乌斯&plus;搜索&rpar;

    hdu 5468 Puzzled Elena   /*快速通道*/ Sample Input 5 1 2 1 3 2 4 2 5 6 2 3 4 5   Sample Output Case #1: ...

  5. HDU 4499&period;Cannon 搜索

    Cannon Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Subm ...

  6. HDU 6627 equation &lpar;分类讨论&rpar;

    2019 杭电多校 5 1004 题目链接:HDU 6627 比赛链接:2019 Multi-University Training Contest 5 Problem Description You ...

  7. HDU 1045 &lpar;DFS搜索&rpar;

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1045 题目大意:在不是X的地方放O,所有O在没有隔板情况下不能对视(横行和数列),问最多可以放多少个 ...

  8. HDU 1180 &lpar;BFS搜索&rpar;

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1180 题目大意:迷宫中有一堆楼梯,楼梯横竖变化.这些楼梯在奇数时间会变成相反状态,通过楼梯会顺便到达 ...

  9. HDU 2531 &lpar;BFS搜索&rpar;

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2531 题目大意: 你的身体占据多个点.每次移动全部的点,不能撞到障碍点,问撞到目标点块(多个点)的最 ...

随机推荐

  1. Windows线程漫谈界面线程和工作者线程

    每个系统都有线程,而线程的最重要的作用就是并行处理,提高软件的并发率.针对界面来说,还能提高界面的响应力. 线程分为界面线程和工作者线程,界面实际就是一个线程画出来的东西,这个线程维护一个“消息队列” ...

  2. &lbrack;UI&rsqb;实用案例--Shape绘制实用圆圈

    Android允许通过xml定义资源,常见的事string,id,integer,dimen等,也可以定义一些图片资源,比如用来做几何的矢量图就非常好用,其中有许多的细节问题,具体需求可以再结合goo ...

  3. 【转】简析SynchronousQueue,LinkedBlockingQueue,ArrayBlockingQueue

    转载地址:http://blog.csdn.net/mn11201117/article/details/8671497 SynchronousQueue SynchronousQueue是*的,是 ...

  4. Hortonworks HDP Sandbox定制&lpar;配置&rpar;开机启动服务&lpar;组件&rpar;

    定制Hortonworks HDP开机启动服务能够这样做:本文原文出处: http://blog.csdn.net/bluishglc/article/details/42109253 严禁不论什么形 ...

  5. UNIX&sol;Linux进程间通信IPC---管道--全总结&lpar;实例入门&rpar;

    管道 一般,进程之间交换信息的方法只能是经由fork或exec传送打开文件,或者通过文件系统.而进程间相互通信还有其他技术——IPC(InterProcessCommunication) (因为不同的 ...

  6. 2015-12-27 socket的用法

    sk = socket.socket(socket.AF_INET,socket.SOCK_STREAM,0) sk.bind(address) s.bind(address) 将套接字绑定到地址.a ...

  7. Dropout的理解

    https://zhuanlan.zhihu.com/p/23178423 这篇知乎文章讲的比较好,在神经网络权重取平均值和减少神经元之间复杂的共适应关系两个方面分析了为什么dropout可以解决过拟 ...

  8. 理解C&num;的Lock语法意义

    一. 为什么要lock,lock了什么? 当我们使用线程的时候,效率最高的方式当然是异步,即各个线程同时运行,其间不相互依赖和等待.但当不同的线程都需要访问某个资源的时候,就需要同步机制了,也就是说当 ...

  9. 什么是 &period;live&lpar;&rpar;

    很多开发者都知道jQuery的.live()方法,他们大部分知道这个函数做什么,但是并不知道是怎么实现的,所以用的并不那么舒适.而且他们却从未听过还有解除绑定的.live()事件的.die()方法.即 ...

  10. Scrum Meeting 11&period;06

    成员 今日任务 明日计划 用时 徐越 学习ListView+simpleAdapter,actionBar.阅读并修改前端代码 继续修改前端代码.完善数据库 4h 赵庶宏  构建后端数据库,进行完善 ...