博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ZOJ 1204 一个集合能组成多少个等式
阅读量:4606 次
发布时间:2019-06-09

本文共 3003 字,大约阅读时间需要 10 分钟。

Additive equations

Time Limit : 20000/10000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 22   Accepted Submission(s) : 12
Problem Description
    We all understand that an integer set is a collection of distinct integers. Now the question is: given an integer set, can you find all its addtive equations? To explain what an
additive equation is, let's look at the following examples:
    1+2=3 is an additive equation of the set {1,2,3}, since all the numbers that are summed up in the left-hand-side of the equation, namely 1 and 2, belong to the same set as their sum 3 does. We consider 1+2=3 and 2+1=3 the same equation, and will always output the numbers on the left-hand-side of the equation in ascending order. Therefore in this example, it is claimed that the set {1,2,3} has an unique additive equation 1+2=3.
    It is not guaranteed that any integer set has its only additive equation. For example, the set {1,2,5} has no addtive equation and the set {1,2,3,5,6} has more than one additive equations such as 1+2=3, 1+2+3=6, etc. When the number of integers in a set gets large, it will eventually become impossible to find all the additive equations from the top of our minds -- unless you are John von Neumann maybe. So we need you to program the computer to solve this problem.

 

Input

The input data consists of several test cases.
The first line of the input will contain an integer N, which is the number of test cases.
Each test case will first contain an integer M (1<=M<=30), which is the number of integers in the set, and then is followed by M distinct positive integers in the same line.

Output

For each test case, you are supposed to output all the additive equations of the set. These equations will be sorted according to their lengths first( i.e, the number of integer being summed), and then the equations with the same length will be sorted according to the numbers from left to right, just like the sample output shows. When there is no such equation, simply output "Can't find any equations." in a line. Print a blank line after each test case.

Sample Input
33 1 2 33 1 2 56 1 2 3 5 4 6

Output for the Sample Input

1+2=3Can't find any equations.1+2=31+3=41+4=51+5=62+3=52+4=61+2+3=6

 

 

 

Source
Zhejiang University Local Contest 2002, Preliminary
 
题意:  输入一个集合 看这个集合中能组成多少个等式    注意1+2=3和2+1=3一样   
另外输出首先按照参与元素个数多少排序    如果参与个数相同 则按照元素大小排序 如上面样例
 
思路:
DFS 
DFS 搜索
 
#include
#include
#include
#include
using namespace std;int st[100],n,vis[100];string str;string ans[33][6000];int a[33];int cnt=0;void change(int mid){ int num=0; char ss[22]; while(mid) { ss[num++]=mid%10+'0'; mid=mid/10; } for(int i=num-1;i>=0;i--) str+=ss[i];}void out(){ int i,flag=1; cnt=0; str.clear(); for(i=0;i
st[n-1]) return ; for(i=pos+1;i

 

转载于:https://www.cnblogs.com/jiangu66/p/3201181.html

你可能感兴趣的文章
建立备份策略的重要性
查看>>
小白用户如何轻松上云 -我的轻量应用服务器探索记
查看>>
BCG与阿里研究院等联合揭秘中国互联网经济:成功的关键是什么?
查看>>
发力IoT领域 Marvell注重生态系统发展
查看>>
数据中心网络布线工程必备七大件
查看>>
20个问题揭穿冒牌数据科学家
查看>>
你应该知道的 RPC 原理
查看>>
Ubuntu安装词典
查看>>
KVM虚拟机在线添加网卡
查看>>
Spring解析
查看>>
支付宝签约教程及注意事项
查看>>
Linux Glibc溢出漏洞凶猛来袭 可让***者获取操作系统的控制权限
查看>>
设计模式之原则
查看>>
Maven修改全局和局部JDK版本
查看>>
设计模式——组合模式(Composite Pattern)
查看>>
java设计模式之——代理模式
查看>>
php页面防止重复提交
查看>>
Perl DBI模块的例子
查看>>
python中str和repr区别
查看>>
升级win10后无法使用桥接网络解决方法
查看>>