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 ...
随机推荐
-
51nod1364 最大字典序排列
不断的在cur的后面找最大的符合条件的数扔到cur的前面. 用线段树维护操作就可以了. #include<cstdio> #include<cstring> #include& ...
-
POJ 1330 Nearest Common Ancestors(求最近的公共祖先)
题意:给出一棵树,再给出两个节点a.b,求离它们最近的公共祖先.方法一: 先用vector存储某节点的子节点,fa数组存储某节点的父节点,最后找出fa[root]=0的根节点root. 之后 ...
-
Oracle游标使用详解
转自:http://www.cnblogs.com/sc-xx/archive/2011/12/03/2275084.html 声明游标:CURSOR cursor_name IS select_st ...
-
关于微信内置浏览器在ios上播放提示音的经验分享
document.addEventListener("WeixinJSBridgeReady", function () { window.audio= new Audio() w ...
-
2019.03.29 NOIP训练 友好国度(点分治+容斥)
传送门 思路: 直接上点分治+容斥计算每个因数对应的贡献即可. 代码: #include<bits/stdc++.h> #define ri register int using name ...
-
WinForm timer 控件
timer 控件:按用户定义的时间间隔引发的事件 属性: Enabled 是否启用: Interval 事件发生的事件间隔,单位是毫秒 事件只有一个:Tick 事件经过指定的时间间隔发生 打开一个窗口 ...
-
scrollIntoView()方法
该方法用于建立一个锚点,点击锚点,会跳到相应的内容,且该内容头部与浏览器头部平齐 实例: <html> <head> <title>TODO supply a ti ...
-
VSCode Web Developement for Javascript. Must have plugins.
Es6 Javascript front-end web developemnt must have plugins Prettier - Code Formatter Javascript (ES6 ...
-
jQuery.Easyui 三层菜单的实现
有图才有真相: 三层导航菜单JSON 数据格式如下: ].panel('options').title; $('#wnav').accordion('select', t); } // 初始化左 ...
-
Angular关于$anchorScroll的定位滚动
以下是实现定位滚动的代码: <!DOCTYPE html> <html lang="en" ng-app="app"> <head ...