题目链接

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. 数据结构之B进制(确定进制)

    #include <cstdio> int max_num(int n) { int max=0; while(n) { int k=n%10; if(k>max) max=k; n ...

  2. Tomcat闪退的问题

    问题:双击tomcat bin下的startup.bat,tomcat的窗口一闪而过,未成功启动: 原因是:在启动tomcat是,需要读取环境变量和配置信息,缺少了这些信息就会导致了tomcat的闪退 ...

  3. HTTPS 证书配置

    HTTPS 证书配置 现在阿里云和腾讯云都支持申请 HTTPS 证书,这里不再提,有需要的可自行google解决方案. 本文主要介绍的是通过 letsencrypt 申请免费的HTTPS证书,并将其配 ...

  4. Java之JMX 详解

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt194 一.JMX简介 JMX是一种JAVA的正式规范,它主要目的是让程序有被 ...

  5. UX是什么?

    UX(用户体验),操作过安卓手机或者苹果手机的系统吧?那么操作过程的整体体验就叫UX,而操作过程中所看到的界面颜色啦,图案,字体大小啦等等都属于UI设计,而交互设计(Interaction Desig ...

  6. 集美大学网络1413第十一次作业成绩(团队七) -- Alpha冲刺之事后诸葛亮

    题目 团队作业7--Alpha冲刺之事后诸葛亮 团队作业7成绩  团队/分值 设想和目标 计划 资源 变更管理 设计/实现 测试/发布 团队角色. 管理.合作 总结 讨论照片 团队成员 角色.贡献 总 ...

  7. 【Alpha】——Fourth Scrum Meeting

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

  8. 201521123087 《java程序设计》 第七周学习总结

    1. 本周学习总结 2. 书面作业 ArrayList代码分析1.1 解释ArrayList的contains源代码                                           ...

  9. 201521123071 《JAVA程序设计》第四周学习总结

    1. 本周学习总结 1.1 1.2 在本周的学习中,主要学习了以下几点: 注释的应用,并能在Eclipse中查看 继承的基本定义,关键字super的用法,覆盖与重载 多态与is-a,instanceo ...

  10. 201521123122 《java程序设计》 第四周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. 这个思维导图比较简单,详细内容点击此处 2. 书面作业 注释的应用 使用类的注释与方法的注释 ...