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 ...
随机推荐
- 什么是web标准
Web Standards Standards是个复数,就知道他是有好几个标准或者规范组成的,分别是:结构规范 XML ,XHTML;表现规范 CSS;行为规范 DOM,ECMAScript; 上面是 ...
- Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Chinese_PRC_CI_AS" in the equal to operation.
Scenario : 这个问题是我的存储过程中用到临时表时发生的. 应该是sql server 服务器的排序规则 (SQL_Latin1_General_CP1_CI_AS ) 与数据库的排序规则(C ...
- ODI 11g Studio 修改界面语言
{ODI_HOME}/oracledi\client\ide\bin找到ide.conf 添加AddVMOption -Duser.language=enAddVMOption -Duser.regi ...
- Oracle EBS-SQL (WIP-14):检查车间需求与BOM差异对照.sql
select a.*, b.BOM定额, a.WIP定额 - b.BOM定额 差异 from (select WE.WIP_ENTITY_NAME ...
- 本地拦截genymotion或者Android模拟器的网络请求
我们在主机上面运行了Burp或者fiddler,那么代理已经监听在本机的8080端口了. 那么我们需要在模拟器中进行如下设置: 1.在设置中,长按当前连接的wifi网络,弹出如下: 2. 点击修改网络 ...
- 2014上半年acm总结(1)(入门+校赛)
大一下学期才开始了acm,不得不说有一点迟,但是acm确实使我的生活充实了很多,,不至于像以前一样经常没事干= = 上学期的颓废使我的c语言学的渣的一笔..靠考前突击才基本掌握了语法 寒假突然醒悟, ...
- 使用kd-tree加速k-means
0.目录 前置知识 思路介绍 详述 1 确定h的中心点 2 算法步骤 java实现 1.前置知识 本文内容基于<Accelerating exact k-means algorithms wit ...
- 读取系统执行状态的shell脚本
近期在学习shell.老大让写一个读取系统配置信息的脚本当作练习和工作验收,我就写了这么一个脚本,读取操作系统,内核,网卡,cpu,内存,磁盘等信息,目的是让看的人一眼就能看出这台机子的配置以及眼下的 ...
- POJ2229 Sumsets 【递归】
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 13210 Accepted: 5300 Descrip ...
- bootstarp(carousel)组件
##### 1.5.1.Bootstrap中轮播图插件叫作Carousel ##### 1.5.2.基本的轮播图实现 ```html <!-- 以下容器就是整个轮播图组件的整体, 注意该盒子必须 ...