Equation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 92    Accepted Submission(s): 24
Problem Description
Little Ruins is a studious boy, recently he learned addition operation! He was rewarded some number bricks of 1 to 9 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=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, x, y and z will be single digit number.

Two addition equations are different if any number of x, y and z is different.

Please help little Ruins to calculate the maximum number of different addition equations.

 
Input
First line contains an integer T, which indicates the number of test cases.

Every test case contains one line with nine integers, the ith integer indicates the number of bricks of i.

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
 
Source
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  5960 5959 5958 5957 5956 
 

Statistic | Submit | Discuss | Note

题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=5937

题目大意:

  给1~9 9个数字,每个数字有Xi个,问总共能凑成多少个不同的等式A+B=C(A B C均为1位,1+2=3和2+1=3视为不同等式)

题目思路:

  【DFS+剪枝】

  这题本来想成网络流,建图建不出来最后只能靠爆搜+剪枝过了【我太弱了,第一名15ms过的。我234ms。可能有正解吧】

  首先列出等式总共就36种,每种数字最多需要17-i个,然后我就这样爆搜+剪枝T的死死的。

  后来经学长点拨说可以缩到20(视为有序,1+2=3和2+1=3视为同一种,乘上1或2)

  然后我又调整了下搜索的顺序,然后就。。过了。

  【程序里a是等式,b是三个数,c是能够用几次,d是前i个最多能组成多少等式】

 //
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 24
#define M 1004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
int num[];
int a[N]={
,
,
,,
,,
,,,
,,,
,,,,
,,,};
int b[N][]={
{,,},
{,,},
{,,},{,,},
{,,},{,,},
{,,},{,,},{,,},
{,,},{,,},{,,},
{,,},{,,},{,,},{,,},
{,,},{,,},{,,},{,,}};
int c[N]={
,
,
,,
,,
,,,
,,,
,,,,
,,,};
int d[N]={
,
,
,,
,,
,,,
,,,
,,,,
,,,};
void dfs(int top,int le,int l)
{
if((ans-top)*>=le)return;
if(ans-top>=d[l-])return;
int i,x,y,z;
ans=max(ans,top);
for(i=l-;i>=;i--)
{
x=b[i][],y=b[i][],z=b[i][];
num[x]--,num[y]--,num[z]--;
if(num[x]>= && num[y]>= && num[z]>=)
dfs(top+,le-,i);
if(c[i]>)
{
num[x]--,num[y]--,num[z]--;
if(num[x]>= && num[y]>= && num[z]>=)
dfs(top+,le-,i);
num[x]++,num[y]++,num[z]++;
}
num[x]++,num[y]++,num[z]++;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
// init();
// for(scanf("%d",&cass);cass;cass--)
for(scanf("%d",&cas),cass=;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d%d",&n,&m))
{
printf("Case #%d: ",cass);
z=;ans=;
for(i=;i<;i++)
{
scanf("%d",&num[i]);
num[i]=min(num[i],-i);
z+=num[i];
}
if(num[])i=;
else if(num[])i=;
else if(num[])i=;
else if(num[])i=;
else if(num[])i=;
else if(num[])i=;
else if(num[])i=;
else if(num[])i=;
dfs(,z,i);
printf("%d\n",ans);
}
return ;
}
/*
// //
*/

HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))的更多相关文章

  1. HDU 5963 朋友 【博弈论】 (2016年中国大学生程序设计竞赛(合肥))

    朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Descr ...

  2. HDU 5969 最大的位或 【贪心】 (2016年中国大学生程序设计竞赛(合肥))

    最大的位或 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem De ...

  3. HDU 5968 异或密码 【模拟】 2016年中国大学生程序设计竞赛(合肥)

    异或密码 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Des ...

  4. HDU 5961 传递 【图论+拓扑】 (2016年中国大学生程序设计竞赛(合肥))

    传递 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)     Problem ...

  5. HDU 5965 扫雷 【模拟】 (2016年中国大学生程序设计竞赛(合肥))

    扫雷 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submissi ...

  6. HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))

    Difference Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  7. HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))

    Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  8. HDU 5938 Four Operations 【贪心】(2016年中国大学生程序设计竞赛(杭州))

    Four Operations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. HDU 5935 Car 【模拟】 (2016年中国大学生程序设计竞赛(杭州))

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

随机推荐

  1. iOS开发——音频篇——音效的播放

    一.简单介绍 简单来说,音频可以分为2种 (1)音效 又称“短音频”,通常在程序中的播放时长为1~2秒 在应用程序中起到点缀效果,提升整体用户体验 (2)音乐 比如游戏中的“背景音乐”,一般播放时间较 ...

  2. ReactiveCocoa 入门学习 (一)

    引言 现在由于需求的不断发展,MVC这个经典的框架由于Controller的任务越来越多,显得"臃肿"了,网上又推出了新的框架,比如MVVM,ReactiveCocoa, 今天就来 ...

  3. 浅谈c#接口的问题,适合新手来了解

    这段时间的项目有用到接口,开始不是特别理解接口,只是单单知道接口定义非常简单,甚至觉得这个接口只是多此一举(个人开发的时候).现在开始团队开发,才发现接口原来是这么的重要和便捷! 接下来就来谈谈我这段 ...

  4. java新手笔记20 抽象类模板(letter)

    1.抽象类 package com.yfs.javase; //信模板 public abstract class Templater { public abstract String toName( ...

  5. java之泛型潜在错误

    如果使用带泛型声明的类时,没有传入类型参数,那么这个类型参数默认是声明该参数时指定的第一个上限类型,这个类型参数被称为raw type(原始类型 ). eg:     public class Lis ...

  6. STL unique使用问题

    string strs[] = {"one","one","two","three","three" ...

  7. session绑定线程

  8. ellang 中进程异步通信中的信箱与保序

    erlang 进程通讯中 执行到 receive 语句时 如果信箱没有消息可以匹配时会暂停等待消息. go() -> register(echo, spawn(test_pid,loop,[]) ...

  9. web开发工具IDE

    1.NetBeans 2.Zend Studio 3.JetBrains WebStorm 4.JetBrains PhpStorm 5.Koala 6.Ionic Lab 7.sublime 8.N ...

  10. 【python】三个变量互换值

    >>> x = 1>>> y = 2>>> z = 3>>> y3>>> z1 大写的帅字! (来自小甲鱼习题 ...