HDU 4403 A very hard Aoshu problem (DFS暴力)
题意:给你一个数字字符串。问在字符串中间加‘=’、‘+’使得‘=’左右两边相等。
1212 : 1+2=1+2, 12=12。
12345666 : 12+3+45+6=66。 1+2+3+4+56=66;
#include<stdio.h>
#include<string.h>
#include<string>
#include<map>
#include<stack>
#include<math.h>
#include<queue>
#include<vector>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define M 20005
vector<int>Ga,Gb;
char s[50];
int l,len,ans;
int a[M],b[M];
int num[55][55];
int get_num(int x,int y)
{
int sum=0;
for(int i=x;i<=y;i++)
sum=sum*10+s[i]-'0';
return sum;
}
void dfs2(int i,int lsum,int rsum)
{
if(i>=len)
{
if(lsum==rsum)
ans++;
return;
}
for(int k=i;k<len;k++)
dfs2(k+1,lsum,rsum+num[i][k]);
}
void dfs1(int i,int sum)
{
if(i>=l)
dfs2(i,sum,0);
for(int k=i;k<l;k++)
dfs1(k+1,sum+num[i][k]);
}
int main()
{
while(scanf("%s",s))
{
if(s[0]=='E')
break;
ans=0;
int i,j,k;
len=strlen(s);
for(i=0;i<len;i++)
{
for(j=i;j<len;j++)
{
num[i][j]=get_num(i,j);
}
}
for(int a=1;a<len;a++)
{
l=a;
dfs1(0,0);
}
printf("%d\n",ans);
}
return 0;
}
/*
1212
12345666
1235
*/
HDU 4403 A very hard Aoshu problem (DFS暴力)的更多相关文章
- HDU 4403 A very hard Aoshu problem(DFS)
A very hard Aoshu problem Problem Description Aoshu is very popular among primary school students. I ...
- HDU 4403 A very hard Aoshu problem(dfs爆搜)
http://acm.hdu.edu.cn/showproblem.php?pid=4403 题意: 给出一串数字,在里面添加一个等号和多个+号,使得等式成立,问有多少种不同的式子. 思路: 数据量比 ...
- HDU 4403 A very hard Aoshu problem
暴力$dfs$. 先看数据范围,字符串最长只有$15$,也就是说枚举每个字符后面是否放置“$+$”号的复杂度为${2^{15}}$. 每次枚举到一种情况,看哪些位置能放“$=$”号,每个位置都试一下, ...
- A very hard Aoshu problem(dfs或者数位)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4403 A very hard Aoshu problem Time Limit: 2000/1000 ...
- HDU 3699 A hard Aoshu Problem(暴力枚举)(2010 Asia Fuzhou Regional Contest)
Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...
- HDU4403 A very hard Aoshu problem DFS
A very hard Aoshu problem Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu 1010 Tempter of the Bone(dfs暴力)
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...
- 【HDOJ】4403 A very hard Aoshu problem
HASH+暴力. /* 4403 */ #include <iostream> #include <cstdio> #include <cstring> #incl ...
- HDU 3699 A hard Aoshu Problem (暴力搜索)
题意:题意:给你3个字符串s1,s2,s3;要求对三个字符串中的字符赋值(同样的字符串进行同样的数字替换), 替换后的三个数进行四则运算要满足左边等于右边.求有几种解法. Sample Input 2 ...
随机推荐
- vs2012打开低版本项目时 出现vs2012警告未能加载包“visual c++ package 解决办法
vs2012 打开 vs2010 项目时 提示的 错误信息. 解决办法 是下载一个 vs2012的 一个补丁包 http://www.microsoft.com/en-us/download/deta ...
- 读懂diff(转载)
作者: 阮一峰 日期: 2012年8月29日 diff是Unix系统的一个很重要的工具程序. 它用来比较两个文本文件的差异,是代码版本管理的基石之一.你在命令行下,输入: $ diff <变动前 ...
- Docker网络基础:快速指南
Docker网络基础:快速指南 原文连接:http://blogxinxiucan.sh1.newtouch.com/2017/07/30/Docker网络基础:快速指南/ 了解有关扩展网络功能的默认 ...
- HDU——1257最少拦截系统(贪心)
最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- HDU——1395 2^x mod n = 1(取模运算法则)
2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- Linux rpm 命令参数使用
RPM是RedHat Package Manager(RedHat软件包管理工具)类似Windows里面的“添加/删除程序” rpm 执行安装包二进制包(Binary)以及源代码包(Source)两种 ...
- 我要好offer之 C++大总结
0. Google C++编程规范 英文版:http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml 中文版:http://zh-g ...
- PXC集群资料整理
1.mysql集群方案对比 方案1 NDBCluster 参考:https://www.cnblogs.com/kevingrace/p/5685371.html?utm_source=itdad ...
- “百度杯”CTF比赛 十月场_Login
题目在i春秋ctf大本营 打开页面是两个登录框,首先判断是不是注入 尝试了各种语句后,发现登录界面似乎并不存在注入 查看网页源代码,给出了一个账号 用帐密登陆后,跳转到到member.php网页,网页 ...
- Oracle单个datafile大小的限制
http://blog.itpub.net/30776559/viewspace-2146790/