HDU 4403 A very hard Aoshu problem(DFS)
A very hard Aoshu problem
Given a serial of digits, you must put a '=' and none or some '+' between these digits and make an equation. Please find out how many equations you can get. For example, if the digits serial is "1212", you can get 2 equations, they are "12=12" and "1+2=1+2". Please note that the digits only include 1 to 9, and every '+' must have a digit on its left side and right side. For example, "+12=12", and "1++1=2" are illegal. Please note that "1+11=12" and "11+1=12" are different equations.
12345666
1235
END
2
0
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#define ms(a) memset(a,0,sizeof a)
using namespace std;
int sum[][];
vector<int> v;
string s;
int ans;
//处理等号右边
void dfs2(int lsu,int su,int l)//等号左边的和,和,起点
{
if(lsu<su)return;
if(l==(int)s.size()&&lsu==su)
{
ans++;
return;
}
for(int i=l+; i<=(int)s.size(); i++)
{
dfs2(lsu,su+sum[l][i-],i);
}
}
//处理等号左边
void dfs1(int su,int l,int r)//和,左,右界
{
if(l==r)
{
dfs2(su,,r);
return;
}
for(int i=l+; i<=r; i++)
{
dfs1(su+sum[l][i-],i,r);
}
}
int main()
{
string::iterator it1,it2;
while(cin>>s)
{
if(s=="END")break;
//ms(sum);
ans=;
if(s.size()==)printf("0\n");
else
{
//预处理,得到某个区间的数值
for(it1=s.begin(); it1!=s.end(); it1++)
{
int t=*it1-'';
sum[it1-s.begin()][it1-s.begin()]=t;
for(it2=it1+; it2!=s.end(); it2++)
{
t=t*+(*it2-'');
sum[it1-s.begin()][it2-s.begin()]=t;
}
}
//1=234566=6,等号的位置
for(it1=s.begin()+; it1!=s.end(); it1++)
{
dfs1(,,it1-s.begin());
}
printf("%d\n",ans);
}
}
return ;
}
HDU 4403 A very hard Aoshu problem(DFS)的更多相关文章
- 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暴力)
题意:给你一个数字字符串.问在字符串中间加'='.'+'使得'='左右两边相等. 1212 : 1+2=1+2, 12=12. 12345666 : 12+3+45+6=66. 1+2+3+4 ...
- 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 ...
- HDU4403 A very hard Aoshu problem DFS
A very hard Aoshu problem Time Limit: 2000/1000 MS (Java/Others) Memory ...
- 【HDOJ】4403 A very hard Aoshu problem
HASH+暴力. /* 4403 */ #include <iostream> #include <cstdio> #include <cstring> #incl ...
- hdu 3699 10 福州 现场 J - A hard Aoshu Problem 暴力 难度:0
Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...
- HDOJ(HDU).1016 Prime Ring Problem (DFS)
HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- 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 ...
随机推荐
- 动态代理 原理简析(java. 动态编译,动态代理)
动态代理: 1.动态编译 JavaCompiler.CompilationTask 动态编译想理解自己查API文档 2.反射被代理类 主要使用Method.invoke(Object o,Object ...
- RMAN duplicate from active 时遭遇 ORA-17627 ORA-12154
最近在从活动数据库进行异机克隆时碰到了ORA-17629,ORA-17627,ORA-12154的错误,起初以为是一个Bug呢.Oracle Bug着实太多了,已经成了习惯性思维了.汗!错误提示是无法 ...
- Effective C++(12) 复制对象时要复制每一个成员
问题聚焦: 负责拷贝的两个操作:拷贝构造函数和重载赋值操作符. 一句话总结,确保被拷贝对象的所有成员变量都做一份拷贝. Demo void logCall(const std::string&am ...
- JAVA修饰符类型(转帖)
JAVA修饰符类型(public,protected,private,friendly) public的类.类属变量及方法,包内及包外的任何类均可以访问:protected的类.类属变量及方法,包内的 ...
- 使用with ties查询并列的数据
select top 1 with ties name,stuId,sex,score from stuInfo order by score desc
- Swift之函数语法详解
函数 函数是用来完成特定任务的独立的代码块.你给一个函数起一个合适的名字,用来标识函数做什么,并且当函数需要执行的时候,这个名字会被“调用”. Swift 统一的函数语法足够灵活,可以用来表示任何函数 ...
- Python语言在企业级应用上的十大谬误
英文原文:https://www.paypal-engineering.com/2014/12/10/10-myths-of-enterprise-python/ 翻译原文:http://www.os ...
- [置顶] Android事件—单选按键和下拉按键
在平常的开发中单选按键和下拉按键是非常常用的2个点击事件.首先介绍下单选按键 1:单选按键,单选的主键是radiogroup 这个主键也是很重要的 首先介绍下主键的布局 <?xml versio ...
- 批量转换cue文件编码
之前在网上下载的无损(flac.ape),好多都是整盘的,也就是说一个flac或ape文件搭配一个cue分轨文件,这个文件记录着在不同时间段是哪一首歌曲. 由于之前的操作都是在windows下进行的, ...
- Js面向对象编程
Js面向对象编程 1. 什么是面向对象编程? 我也不说不清楚什么是面向对象,反正就那么回事吧. 编程有时候是一件很快乐的事,写一些小游戏,用编程的方式玩游戏等等 2. Js如何定义一个 ...