uva-10344
题意:
枚举23点,注意,数字也是可以枚举的,wa了一次
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<queue>
#include<map>
#include<memory.h>
#include <math.h>
#include<time.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define N 12
int vis[N];
int a[N];
int b[N];
int n;
int final = ; void dfs(int cur, int total)
{
if(cur == && total == )
{
final = ;
return;
}
for(int i = ; i < && !final; i++)
{
if(vis[i])
continue; vis[i] = ;
if(cur != )
{
dfs(cur + , total - a[i]);
dfs(cur + , total + a[i]);
dfs(cur + , total * a[i]);
}
else
{
dfs(cur + , a[i]);
}
vis[i] = ;
} }
int main(const int argc, char** argv)
{
freopen("d:\\1.txt", "r", stdin);
while (scanf("%d %d %d %d %d", a, a + , a + , a + , a + ))
{
if(a[] || a[] || a[] || a[])
{
final = ;
memset(vis, , sizeof(vis));
dfs(, );
if(final)
cout << "Possible" << endl;
else
cout << "Impossible" << endl; }
else
{
return ;
}
}
return ;
}
uva-10344的更多相关文章
- uva 10344 23 out of 5 凑运算结果 全排列+dfs
五个数三个运算符号,排列之后凑成结果为23,不考虑优先级. 很水,数据量也不大,先生成五个数的全排列,用dfs找出结果能否为23即可. 代码: #include <cstdio> #inc ...
- uva10344 23 out of 5
Your task is to write a program that can decide whether you can nd an arithmetic expression consisti ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
- UVA - 1625 Color Length[序列DP 代价计算技巧]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
随机推荐
- HDU1702:ACboy needs your help again!
ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU 4638 树状数组 想法题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4638 解题思路: 题意为询问一段区间里的数能组成多少段连续的数.先考虑从左往右一个数一个数添加,考虑当 ...
- 1010. Radix (25) pat
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...
- ACM中的取模
取模本身的性质:(之前有一篇博客写过)三则运算(+,-,*)过程中的取模与最后的取模一样(前提是最后不超long long(或int) 范围,所以为防止超范围,直接对三则运算中的过程取模) 然后就是A ...
- 《DSP using MATLAB》Problem 3.6
逆DTFT定义如下: 需要求积分,
- Python类之魔术方法
一.什么是魔术方法? 在Python的方法,我们经常会遇见__XXX__(),这样的方法,我们一般称为"魔术方法",赶紧搬个小板凳,我们一起来看看魔术方法有啥神奇的地方,这些方法又 ...
- NOSQL之MONGODB
MongoDB 基于分布式文件存储的数据库.由 C++ 语言编写.旨在为 WEB 应用提供可扩展的高性能数据存储解决方案,它是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富, ...
- cookie、localStorage、sessionStorage 的生命周期
生命周期 存储 生命周期 cookie 没有设置 expires 选项时,cookie 的生命周期仅限于当前会话中,关闭浏览器意味着这次会话的结束,所以会话 cookie 仅存在于浏览器打开状态之下. ...
- R(4) read/write
write.table() 数据导入导出最常用的方式是使用read.table()函数和write.table()处理CSV文件的导入导出,read.table()和write.table()可以处理 ...
- 捕获长时间不提交的SQL语句
/* Formatted on 2014/5/19 17:16:16 (QP5 v5.240.12305.39476) */ SELECT s.sid, s.serial#, ss.sql_text ...