HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))
Equation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 92 Accepted Submission(s): 24Problem DescriptionLittle 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.
InputFirst 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≤100OutputFor 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 Input3
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 0Sample OutputCase #1: 2
Case #2: 6
Case #3: 2SourceRecommend
题目链接:
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年中国大学生程序设计竞赛(杭州))的更多相关文章
- HDU 5963 朋友 【博弈论】 (2016年中国大学生程序设计竞赛(合肥))
朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Descr ...
- HDU 5969 最大的位或 【贪心】 (2016年中国大学生程序设计竞赛(合肥))
最大的位或 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem De ...
- HDU 5968 异或密码 【模拟】 2016年中国大学生程序设计竞赛(合肥)
异或密码 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Des ...
- HDU 5961 传递 【图论+拓扑】 (2016年中国大学生程序设计竞赛(合肥))
传递 Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem ...
- HDU 5965 扫雷 【模拟】 (2016年中国大学生程序设计竞赛(合肥))
扫雷 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submissi ...
- HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))
Difference Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))
Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU 5938 Four Operations 【贪心】(2016年中国大学生程序设计竞赛(杭州))
Four Operations Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 5935 Car 【模拟】 (2016年中国大学生程序设计竞赛(杭州))
Car Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
随机推荐
- C++ 变量转换
atoi,atol,strtod,strtol,strtoul实现类型转换2006-02-13 版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明http://ivanvic.blogb ...
- 基于SSM框架的简易的分页功能——包含maven项目的搭建
新人第一次发帖,有什么不对的地方请多多指教~~ 分页这个功能经常会被使用到,我之前学习的时候找了很多资源,可都看不懂(笨死算了),最后还是在朋友帮助下做出了这个分页.我现在把我所能想到的知识 做了一个 ...
- Dell Remote Access Controller 添加和配置 DRAC/MC 用户
iDRAC设置 单击“Configuration”(配置)选项卡并选择“Users”(用户). 单击“Username”(用户名)列下的 [Available](可用)添加新用户,或单击“Userna ...
- C++11中新特性之:initializer_list详解
C++11提供的新类型,定义在<initializer_list>头文件中. template< class T > class initializer_list; 先说它的用 ...
- 泛型集合List<T> Dictionary<K,V>
List<T>类似于ArrayList,ArrayList的升级版. 各种方法:Sort().Max().Min().Sum()… Dictionary<K,V>类似于Ha ...
- em,pt和px之间的换算
任意浏览器的默认字体高度16px(16像素).所有未经调整的浏览器都符合: 1em=16px.那么12px=0.75em,10px=0.625em.为了简化font-size的换算,需要在css中的b ...
- 禁止选择文本和禁用右键 v2.0
禁止鼠标右键(注:在火狐浏览器没有起到效果作用) <script> function stop() { return false }; document.oncontextmenu = s ...
- STM32之串口通信
一.RS232通信协议 1.概念 个人计算机上的通讯接口之一,由电子工业协会(Electronic Industries Association,EIA) 所制定的异步传输标准接口. 2.电气特性 逻 ...
- aspose.cells根据模板导出excel
又隔十多天没写博客了,最近都在忙项目的事情,公司人事变动也比较大,手头上就又多了一个项目.最近做用aspose.cells根据模板导出excel报价单的功能,顺便把相关的核心记下来,先上模板和导出的效 ...
- C# RichTextBox 获取当前显示部分的文字
int start = richTextBox1.GetCharIndexFromPosition(new Point(0, 0)); int end = richTextBox1.GetCharIn ...