描述
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. Contains Duplicate II 解答

    Question Given an array of integers and an integer k, find out whether there are two distinct indice ...

  2. struct内存对齐

    内存对齐其实是为了在程序运行的时候更快的查找内存而做的一种编译器优化. 我们先看这样一个例子: #include <iostream> using namespace std; struc ...

  3. iOS加密个人见解

    说说常用的加密方式 1.单向加密,譬如 md5 .SHA 但是这种单向加密安全性也不高了,现在cpu.gpu都那么强大,运算速度很快,彩虹表 撞库 还是容易被攻破的. 如果非得用的话,可以md5加盐, ...

  4. HexColor

    // // HexColor.swift // HexColor // // Created by Tuomas Artman on 1.9.2014. // Copyright (c) 2014 T ...

  5. asp.net关于Repeater控件中的全选,批量操作

    今天在Repeater控件中碰到一个全选的操作,于是上网查了一下,找到一个觉得比较好,便记录下来, 界面代码简化之后(全选操作): <script type="text/javascr ...

  6. MVC 全局异常过滤器HandleErrorAttribute

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  7. ios 添加多个target 管理 多个版本文件

    1. 添加一个Target 这里是添加一个Test 项目 这里添加新的target Test与Release 也是同上的操作

  8. B - Numbers That Count

    Description        "Kronecker's Knumbers" is a little company that manufactures plastic di ...

  9. 关于datetime和int 是否可为null的问题

    一个对象的属性中有一个datetime类型的属性,在赋值时未给予赋值,此时系统会分配给它一个最小的时间,不会是null值,与int类型相似,datetime也不会有null类型, 先来看一段代码: n ...

  10. 滑动冲突的补充——Event的流程走向

    一.之前分析的滑动冲突,并没有讲述event事件是如何分发到不同的控件 View的滑动冲突 现在分析一下滑动冲突event事件的流向 假设:  我们的一个事件为  点下——>左滑动一次——> ...