描述
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暴力)的更多相关文章

  1. Nyoj 43 24 Point game 【DFS】

    24 Point game 时间限制:3000 ms  |  内存限制:65535 KB 难度:5 描写叙述 There is a game which is called 24 Point game ...

  2. [NYOJ 43] 24 Point game

    24 Point game 时间限制:3000 ms  |  内存限制:65535 KB 难度:5   描述 There is a game which is called 24 Point game ...

  3. ACM: FZU 2107 Hua Rong Dao - DFS - 暴力

    FZU 2107 Hua Rong Dao Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  4. ACM: Gym 100935G Board Game - DFS暴力搜索

    Board Game Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u  Gym 100 ...

  5. 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 ...

  6. nyoj 1237 最大岛屿(dfs)

    描述 神秘的海洋,惊险的探险之路,打捞海底宝藏,激烈的海战,海盗劫富等等.加勒比海盗,你知道吧?杰克船长驾驶着自己的的战船黑珍珠1号要征服各个海岛的海盜,最后成为海盗王. 这是一个由海洋.岛屿和海盗组 ...

  7. hdu 1010 Tempter of the Bone(dfs暴力)

    Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...

  8. NOIP 2002提高组 选数 dfs/暴力

    1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知 n 个整数 x1,x2,…, ...

  9. hdu 1427 速算24点 dfs暴力搜索

    速算24点 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem De ...

随机推荐

  1. Curvy unity

    想获得当前物体在路径的进度 1. 利用CurvySpline.GetNearestPointTF(); 2. 利用CurvyController.RelativePosition;

  2. poj 3311 Hie with the Pie(状态压缩dp)

    Description The Pizazz Pizzeria prides itself or more (up to ) orders to be processed before he star ...

  3. Python 单词字母顺序不变且所有倒排

    翻出google測试project师的一道题目: 设计一个函数,不论什么语言都能够,实现下面功能: 一个句子,将句子中的单词所有倒排过来,但单词的字母顺序不变.eg.  this is a real ...

  4. LINQ to SQL和Entity Framework对照

    LINQ to SQL和Entity Framework都是一种包括LINQ功能的对象关系映射技术.他们之间的本质差别在于EF对数据库架构和我们查询的类型实行了更好的解耦. 使用EF,我们查询的对象不 ...

  5. 谋哥:研究App排行榜浮出的神器

    昨天发的<App排行榜的秘密>到头条网,阅读量到2万,踩的比顶的多几倍.原因是由于我使用360市场的数据来分析,而且这帮喷子根本不看你分析数据背后的意义,反正看到自己不喜欢的比方" ...

  6. Linux Tomcat7.0安装配置实践总结

    一,安装JDk 先下载jdk,链接http://www.oracle.com/technetwork/java/javase/downloads/index.html,选择相对应平台的JDK.由于笔者 ...

  7. centos7命令行与图形界面启动模式修改

    1.命令启动 systemctl set-default multi-user.target 2.图形界面模式 systemctl set-default graphical.target

  8. jsp基础之 jstl

    JSP标准标签库(JSTL)是一个JSP标签集合,它封装了JSP应用的通用核心功能. JSTL支持通用的.结构化的任务,比如迭代,条件判断,XML文档操作,国际化标签,SQL标签. 除了这些,它还提供 ...

  9. Bluestacks视窗界面调整及内存调整经验

    本文将分享bluestacks视窗界面调整及内存调整的经验,可以有效解决Bluestacks缓慢.卡的问题! 一.bluestacks视窗界面调整 1.进入注册表: 2.找到下图中的键值: 3.修改键 ...

  10. Loader之一:基本原理

    参考APIDEMO及http://developer.android.com/guide/components/loaders.html#app 1.Introduced in Android 3.0 ...