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 ...
随机推荐
- bzoj1864 [Zjoi2006]三色二叉树
Description Input 仅有一行,不超过500000个字符,表示一个二叉树序列. Output 输出文件也只有一行,包含两个数,依次表示最多和最少有多少个点能够被染成绿色. Sample ...
- UESTC_秋实大哥掰手指 2015 UESTC Training for Dynamic Programming<Problem B>
B - 秋实大哥掰手指 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 2048/1024KB (Java/Others) Submit ...
- python刷取CSDN博文访问量之四
python刷取CSDN博文访问量之四 作者:vpoet #coding:utf-8 import requests import urllib2 import re import time def ...
- js点击事件防止用户重复点击执行
点击事件里给button标签加一个自定义属性,存上次点击时间 追问: 求详细代码,JS 真心的没怎么做过 追答: <input type="button" id=&quo ...
- Android学习总结——Service组件
从Service的启动方式上,可以将Service分为Started Service和Bound Service.在使用Service时,要想系统能够找到此自定义Service,无论哪种类型,都需要在 ...
- 数据库的优化tips
数据库 TIPS:: 1.用于记录或者是数据分析的表创建时::使用Id作为主键,1,2,3...表示消息条数.用户账号id用于做外键.一个用户相应唯一个accountId ...
- 登录DSCCC控制台报错提示:安装错误代码: 3
登录DSCCC控制台报错内容:读取安装配置时出错 检查目录服务控制中心状态时出现意外错误. 显示详细资料 隐藏详细资料 安装错误代码: 3 堆栈: com.sun.directory.common.s ...
- [Python笔记][第一章Python基础]
2016/1/27学习内容 第一章 Python基础 Python内置函数 见Python内置函数.md del命令 显式删除操作,列表中也可以使用. 基本输入输出 input() 读入进来永远是字符 ...
- ECSHOP返回顶部的代码 纯CSS超简单
在themes/模板文件夹/library/page_footer.lbi 文件的最末尾加上下面的一段代码 <style>.to_top{width:20px;height:59px;ri ...
- nodejs 计算内存使用率
//计算内存使用率 function calcMem(){ let mem_total = os.totalmem(), mem_free = os.freemem(), mem_used = mem ...