nyoj 43 24 Point game(dfs暴力)
- 描述
-
There is a game which is called Point game. In this game , you will be given some numbers. Your task is to find an expression which have all the given numbers and the value of the expression should be .The expression mustn't have any other operator except plus,minus,multiply,divide and the brackets. e.g. If the numbers you are given is "3 3 8 8", you can give "8/(3-8/3)" as an answer. All the numbers should be used and the bracktes can be nested. Your task in this problem is only to judge whether the given numbers can be used to find a expression whose value is the given number。
- 输入
-
The input has multicases and each case contains one line
The first line of the input is an non-negative integer C(C<=),which indicates the number of the cases.
Each line has some integers,the first integer M(<=M<=) is the total number of the given numbers to consist the expression,the second integers N(<=N<=) is the number which the value of the expression should be.
Then,the followed M integer is the given numbers. All the given numbers is non-negative and less than - 输出
-
For each test-cases,output "Yes" if there is an expression which fit all the demands,otherwise output "No" instead.
- 样例输入
-
- 样例输出
-
Yes
No深搜枚举各种可能。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 1000000
#define inf 1e12
int n;
double v,a[];
bool dfs(int t){
if(t==n){
if(fabs(v-a[n])<1e-){
return true;
}
return false;
}
for(int i=t;i<n;i++){
for(int j=i+;j<=n;j++){
double temp1=a[i];
double temp2=a[j];
a[i]=a[t];
a[j]=temp1+temp2; if(dfs(t+)) return true;//加
a[j]=temp1-temp2; if(dfs(t+)) return true;//减1
a[j]=temp2-temp1; if(dfs(t+)) return true;//减2
a[j]=temp1*temp2; if(dfs(t+)) return true;//乘
if(temp1){//除1
a[j]=temp2/temp1; if(dfs(t+)) return true;
}
if(temp2){//除2
a[j]=temp1/temp2; if(dfs(t+)) return true;
}
a[i]=temp1;//还原
a[j]=temp2;//还原
}
}
return false;
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d%lf",&n,&v);
for(int i=;i<=n;i++){
scanf("%lf",&a[i]);
}
if(dfs()){
printf("Yes\n");
}else{
printf("No\n");
}
}
return ;
}
nyoj 43 24 Point game(dfs暴力)的更多相关文章
- Nyoj 43 24 Point game 【DFS】
24 Point game 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描写叙述 There is a game which is called 24 Point game ...
- [NYOJ 43] 24 Point game
24 Point game 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描述 There is a game which is called 24 Point game ...
- ACM: FZU 2107 Hua Rong Dao - DFS - 暴力
FZU 2107 Hua Rong Dao Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- ACM: Gym 100935G Board Game - DFS暴力搜索
Board Game Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Gym 100 ...
- hdu 5612 Baby Ming and Matrix games(dfs暴力)
Problem Description These few days, Baby Ming is addicted to playing a matrix game. Given a n∗m matr ...
- nyoj 1237 最大岛屿(dfs)
描述 神秘的海洋,惊险的探险之路,打捞海底宝藏,激烈的海战,海盗劫富等等.加勒比海盗,你知道吧?杰克船长驾驶着自己的的战船黑珍珠1号要征服各个海岛的海盜,最后成为海盗王. 这是一个由海洋.岛屿和海盗组 ...
- hdu 1010 Tempter of the Bone(dfs暴力)
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...
- NOIP 2002提高组 选数 dfs/暴力
1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知 n 个整数 x1,x2,…, ...
- hdu 1427 速算24点 dfs暴力搜索
速算24点 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem De ...
随机推荐
- bzoj1630 [Usaco2007 Demo]Ant Counting
Description Bessie was poking around the ant hill one day watching the ants march to and fro while g ...
- 【HDU 5510 Bazinga】字符串
2015沈阳区域赛现场赛第2题 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5510 题意:给定一个由字符串组成的序列,一共n个元素,每个元素是一个不 ...
- 【LeetCode练习题】Maximum Depth of Binary Tree
Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the n ...
- OpenCV MFC 模块间通信
1. 新建MFC项目 点击完成. 2. 添加按钮 在"工具箱"中找到"Button"控件,添加至界面: 2. 配置opencv, 添加colordetecto ...
- IOS 使用dispatch_once 创建单例
+ (instantClass *)sharedClient { static instantClass *_sharedClient = nil; static dispatch_once_t on ...
- ubuntu 文件readonly的问题: W10: Warning: Changing a readonly file 解决办法
日前,笔者遇到一个奇怪且让人蛋疼的问题,借用别人的话"大家在linux上编辑文件的时候,明明是使用的root登录的,可是这种至高无上的权限在按下i的时候被那串红色错误亵渎了W10: Warn ...
- [Python笔记][第二章Python序列-复杂的数据结构]
2016/1/27学习内容 第二章 Python序列-复杂的数据结构 堆 import heapq #添加元素进堆 heapq.heappush(heap,n) #小根堆堆顶 heapq.heappo ...
- eclipse美化,全黑eclipse 保护眼睛
如标题,闲话不多说.有图说明一切.看看这是你想要的嘛? 教程及资源下载地址: http://download.csdn.net/detail/shoneworn/8326097
- JS获取request字符串
function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&] ...
- ASP.NET在实际开发中验证码的用法
在网上有看到很多关于验证码的代码,很多都只是生成一张验证码图片,然而在实际登陆验证模块,验证码要怎么添加进去或者说怎么运用.和实际项目开发中要怎么使用验证码,我自己总结了几点. 一.在实际开发登陆模块 ...