题目链接

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+剪枝】 (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+剪枝)

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

  4. 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: ...

  5. HDU 4499.Cannon 搜索

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

  6. HDU 6627 equation (分类讨论)

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

  7. HDU 1045 (DFS搜索)

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

  8. HDU 1180 (BFS搜索)

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

  9. HDU 2531 (BFS搜索)

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

随机推荐

  1. github如何搜索资料

    进入自己的主页,然后点击explore→trending; 或者google搜索,如github java 后端 请参考:http://mp.weixin.qq.com/s?__biz=MzA4NTQ ...

  2. 系统引导器GRUB

    系统引导器GRUB 理解/boot/grub/grub.conf 1 # grub.conf generated by anaconda 2 # 3 # Note that you do not ha ...

  3. split添加limit参数

    String str = "I love you"; /**这里被分割为I 和love you**/ String[] spiltStr = str.spit(" &qu ...

  4. 点击grid单元格弹出新窗口

    实现功能:点击指定单元格后会弹出新窗口,并且最后一行合计不会触发单元格触发函数 <script type="text/javascript"> grid.on('cel ...

  5. 7-zip 解压

    7-zip 解压 1.引入依赖文件 sevenzipjbinding.jar sevenzipjbinding-Allwindows.jar <!-- https://mvnrepository ...

  6. 我的Markdown的利器——Markdown Here、有道云笔记、iPic

    Markdown逐渐成为大家文章编辑的首选,这里推荐两个比较冷门的Markdown工具. 用什么当做Markdown的主力工具? 网上有很多人推荐的Markdown的工具包括专业的Markdown工具 ...

  7. 我的项目经验总结——CDN镜像:1(初探)

    前言 其实,这个标题有些大,作为一个小白,只是在实际工作中经常听闻我司的CDN服务如何如何牛B……而且我司的云服务还拿到了工信部的CDN牌照……那么,作为一个研发仔,怎么能不去了解和熟悉呢?!不过,这 ...

  8. java 8 总结 之lambda

    lambda表达式 目的:行为参数化 Lambda表达式是简洁地表示可传递的匿名函数的一种方式:它没有名称,但它有参数列表.函数主体.返回类型,可能还有一个可以抛出的异常列表. Lambda的基本语法 ...

  9. 设置为互斥按钮的一组Radio按钮的用法

    设置为互斥按钮的一组Radio,只需要将第一个Radio的Group属性设置为True,并为之映射变量(DDX),其余radio的Group属性设置为False,不需要映射变量. 否则会出现不是互斥按 ...

  10. 【Alpha】——Fourth Scrum Meeting

    一.今日站立式会议照片 二.每个人的工作 成员 昨天已完成的工作 今天计划完成的工作 李永豪 完善添加功能 测试统计功能 郑靖涛 完善删除功能 着手编写报表设计 杨海亮 完善查找功能 协助编写统计功能 ...