How Many Equations Can You Find(dfs)
How Many Equations Can You Find
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 714 Accepted Submission(s): 467
21 1
题解,在一串数字内加+或-,使其等于N的方法数,深搜;
代码:
#include<stdio.h>
#include<string.h>
__int64 ans,N;
int len;
char s[];
void dfs(int t,__int64 sum){
if(t==len){
//printf("%I64d\n",sum);
if(sum==N)ans++;
return;
}
__int64 k=;
for(int i=t;i<len;i++){
k=k*+s[i]-'';
dfs(i+,sum+k);
if(t!=)dfs(i+,sum-k);
}
}
int main(){
while(~scanf("%s%I64d",s,&N)){
len=strlen(s);
ans=;
dfs(,);
printf("%I64d\n",ans);
}
return ;
}
/*#include<stdio.h>
#include<string.h>
__int64 ans,N;
int len;
char s[15];
void dfs(int top,__int64 sum){
if(top==len){//写成N了错的心酸。。。
//printf("%I64d %d\n",sum,len);
if(sum==N)ans++;
return ;
}
__int64 x=0;
for(int i=top;i<len;i++){
x=x*10+s[i]-'0';
dfs(i+1,sum+x);
if(top!=0)dfs(i+1,sum-x);
}
}
int main(){
while(~scanf("%s%I64d",s,&N)){
len=strlen(s);
//printf("%d\n",len);
ans=0;
dfs(0,0);
printf("%I64d\n",ans);
}
return 0;
}*/
How Many Equations Can You Find(dfs)的更多相关文章
- HDOJ(HDU).2266 How Many Equations Can You Find (DFS)
HDOJ(HDU).2266 How Many Equations Can You Find (DFS) [从零开始DFS(9)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零 ...
- HDU 2266 How Many Equations Can You Find(DFS)
How Many Equations Can You Find Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- B - How Many Equations Can You Find dfs
Now give you an string which only contains 0, 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9.You are asked to add the sig ...
- ZOJ1204——Additive equations(DFS)
Additive equations Description We all understand that an integer set is a collection of distinct int ...
- hdu - 2266 How Many Equations Can You Find (简单dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2266 给一个字符串和一个数n,在字符串中间可以插入+或者 -,问有多少种等于n的情况. 要注意任意两个数之间都可 ...
- HDU5937 Equation(DFS + 剪枝)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5937 Description Little Ruins is a studious boy, ...
- zoj 1204 Additive equations
ACCEPT acm作业 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=204 因为老师是在集合那里要我们做这道题.所以我很是天 ...
- HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))
Equation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 4403 A very hard Aoshu problem(DFS)
A very hard Aoshu problem Problem Description Aoshu is very popular among primary school students. I ...
随机推荐
- webform登录操作中正则表达式运用
关于正则表达式的运用,估计很多人都会觉得这很麻烦.确实很麻烦,太多表达式我也记不住,很多都是临时需要用的时候再去查,有点小学生读小说的架势,不认识的字再去翻字典. 正则表达式严格来说对于程序的功能实现 ...
- jQuery随记
每次申明一个jQuery对象的时候,返回的是jQuery.prototype.init对象,很多人就会不明白,init明明是jQuery.fn的方法啊,实际上这里不是方法,而是init的构造函数,因为 ...
- omnibus方式部署gitlab
omnibus方式部署gitlab Posted on 2015 年 1 月 10 日 4233 Views 这几天折腾搭建git服务器,选择了比较流行的gitlab,一开始就直奔一键安装脚本去了 ...
- nginx启动关闭
[root@localhost sbin]# ./nginx -s reload [root@localhost sbin]# ./nginx -s stop [root@localhost sbin ...
- ros消息时间同步与回调
转载自http://blog.csdn.net/zyh821351004/article/details/47758433 方式一: 全局变量形式 : TimeSynchronizer 步骤: 1. ...
- 微软build 2015
1.apple Object-C项目和安卓项目经过移植可以运行在windows上,演示看起来有些卡. 2.平台大统一,Universal Windows App,10亿台设备,这个很重要,以后恐怕离不 ...
- bootstrap-js(4)标签页
实例 标签页(Tab)在 Bootstrap 导航元素 一章中介绍过.通过结合一些 data 属性,您可以轻松地创建一个标签页界面. 通过这个插件您可以把内容放置在标签页或者是胶囊式标签页甚至是下拉菜 ...
- vs2010快捷方式
[窗口快捷键] Ctrl+W,W: 浏览器窗口 Ctrl+W,S: 解决方案管理器 Ctrl+W,C: 类视图 Ctrl+W,E: 错误列表 Ctrl+W,O: 输出视图 trl+W,P: ...
- ORA-600[kcratr_scan_lastbwr]逻辑坏块解决
数据库版本: 11.2.0.3 问题现象: 今天在启动一台测试数据库的时候,发现db不能open,报错如下: ERROR at line 1: ORA-00600: internal error co ...
- 安装jdk和tomcat
安装jdk和tomcat 1,准备工作 虚拟机 VMware :liunx系统镜像 bebian :连接操作软件 putty: 开源图像FTP客户端winspc: Java 语言的软件开发工具包 JD ...