题目例如以下:

Problem I

23 Out of 5

Input: standard input

Output: standardoutput

Time Limit: 1 second

Memory Limit: 32 MB

Your task is to writea program that can decide whether you can find an arithmetic expression consistingof five given numbers
(1<=i<=5) that will yieldthe value 23.

For this problem we will only consider arithmetic expressions of the followingfrom:

 
where : {1,2,3,4,5} -> {1,2,3,4,5} is a bijective function
and  {+,-,*} (1<=i<=4)

Input

The Input consists of 5-Tupelsof positive Integers, each between 1 and 50.

Input is terminated by a line containing five zero's. This line should not beprocessed.

Output

For each 5-Tupel print"Possible" (without quotes) if their exists an arithmetic expression(as described above) that yields 23. Otherwise print "Impossible".

Sample Input

1 1 1 1 1
1 2 3 4 5
2 3 5 7 11
0 0 0 0 0

Sample Output

Impossible
Possible
Possible

也是直接回溯就能够了,只是要注意π是个双射函数(bijective function)。所以要一一相应。不能反复使用,採用一个vis数组标记就可以。

AC的代码例如以下:

UVA 23 out of 5的更多相关文章

  1. uva 10344 23 out of 5 凑运算结果 全排列+dfs

    五个数三个运算符号,排列之后凑成结果为23,不考虑优先级. 很水,数据量也不大,先生成五个数的全排列,用dfs找出结果能否为23即可. 代码: #include <cstdio> #inc ...

  2. uva10344 23 out of 5

    Your task is to write a program that can decide whether you can nd an arithmetic expression consisti ...

  3. UVA 11427 (概率DP+期望)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 题目大意:每晚打游戏.每晚中,赢一局概率p,最多玩n局, ...

  4. UVa 103 - Stacking Boxes(dp求解)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  5. UVA 437 十九 The Tower of Babylon

    The Tower of Babylon Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Subm ...

  6. UVa 1593代码对齐

    原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  7. UVA 10905 Children's Game 孩子的游戏 贪心

    题意:给出N个数,要求把它们拼凑起来,让得到的数值是最大的. 只要分别比较两个数放前与放后的值的大小,排序后输出就可以了. 比如123和56,就比较12356和56123的大小就行了. 写一个比较函数 ...

  8. UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据

    题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...

  9. Uva 11549 - Calculator Conundrum 找规律加map

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

随机推荐

  1. CSS知识点整理(1):CSS语法,层叠次序,选择器,其他重要方面。

    1. css的全称 2. CSS的层叠次序:优先级由低到高 ·浏览器设置 ·外部样式表 或者 内部样式表 —— 就近原则 ·内联样式 3. CSS的3种形式,以及每种形式的语法格式 ——注意样式表的为 ...

  2. opencv3.31+vs2015终于配置成功了

    风萧萧兮易水寒, 熬了几个夜晚,终于把opencv配好了, 来图一 唉试了很多方法,终于成功. 教程和资料会发在个人网站里. 测试 代码 #include <iostream> #incl ...

  3. R语言曲线拟合函数(绘图)

    曲线拟合:(线性回归方法:lm) 1.x排序 2.求线性回归方程并赋予一个新变量     z=lm(y~x+I(x^2)+...) 3.plot(x,y)    #做y对x的散点图 4.lines(x ...

  4. java web 学习笔记 - jsp用的文件上传组件 SmartUpload

    ---恢复内容开始--- 1. SmartUpload 此控件在jsp中被广泛的使用,而FileUpload控件主要是用在框架中 2. 如果想要使用,需要在tomcat的lib目录中,将SmartUp ...

  5. 判断excel是否包含隐藏sheet

    Workbook workbook =new XSSFWorkbook("D:\\文档1.xlsx"); System.out.println(workbook.isSheetHi ...

  6. 【笔记JS/HTML/CSS】CSS3实现鼠标滑动显示动画(transition、transform)

    内容中包含 base64string 图片造成字符过多,拒绝显示

  7. js 动态加载select触发事件

    动态加载select后,手动调用一下 subjectChange函数,模拟触发change事件 function hallidChange(value) { $.ajax({ type: " ...

  8. 【loj6184】无心行挽(虚树+倍增)

    题目链接:https://loj.ac/problem/6184 每次询问给一些关键点,询问树上每个点离最近的关键点的距离(以后称为f(u))最大值是多少. 询问数比较大,但 \sum{K} 和n是一 ...

  9. Luogu P1349 广义斐波那契数列

    解题思路 既然广义斐波那契,而且数据范围这么大,那么我们使用矩阵快速幂来进行求解.大家都知道斐波那契的初始矩阵如下 $$\begin{bmatrix}1&1\\1&0\end{bmat ...

  10. Python&机器学习总结(一)

    ① numpy中np.c_和np.r_ np.r_是按列连接两个矩阵,就是把两矩阵上下相加,要求列数相等,类似于pandas中的concat(). np.c_是按行连接两个矩阵,就是把两矩阵左右相加, ...