http://acm.hdu.edu.cn/showproblem.php?pid=4403

题意:

给出一串数字,在里面添加一个等号和多个+号,使得等式成立,问有多少种不同的式子。

思路:

数据量比较小,直接dfs爆搜答案即可。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std; char s[];
int a[][], tot[], ans;
map<int,int> f; void dfs(int cur, int pre, int sum, int ends, int id)
{
if(cur == ends)
{
if(pre) return;
if(!id) f[sum]++;
else if(f[sum]) ans+=f[sum];
return;
}
dfs(cur+,,sum+pre*+s[cur]-'',ends,id);
dfs(cur+,pre*+s[cur]-'',sum,ends,id);
} int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%s",s) && s[]!='E')
{
ans = ;
int n = strlen(s);
for(int i=;i<n;i++)
{
f.clear();
dfs(,,,i,);
dfs(i,,,n,);
}
printf("%d\n",ans);
}
}

HDU 4403 A very hard Aoshu problem(dfs爆搜)的更多相关文章

  1. HDU 4403 A very hard Aoshu problem(DFS)

    A very hard Aoshu problem Problem Description Aoshu is very popular among primary school students. I ...

  2. 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 ...

  3. HDU 4403 A very hard Aoshu problem

    暴力$dfs$. 先看数据范围,字符串最长只有$15$,也就是说枚举每个字符后面是否放置“$+$”号的复杂度为${2^{15}}$. 每次枚举到一种情况,看哪些位置能放“$=$”号,每个位置都试一下, ...

  4. A very hard Aoshu problem(dfs或者数位)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4403 A very hard Aoshu problem Time Limit: 2000/1000 ...

  5. HDU4403 A very hard Aoshu problem DFS

    A very hard Aoshu problem                           Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  6. 【HDOJ】4403 A very hard Aoshu problem

    HASH+暴力. /* 4403 */ #include <iostream> #include <cstdio> #include <cstring> #incl ...

  7. [HDU 5135] Little Zu Chongzhi's Triangles (dfs暴搜)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5135 题目大意:给你n条边,选出若干条边,组成若干个三角形,使得面积和最大.输出最大的面积和. 先将边 ...

  8. hdu 5506 GT and set(dfs爆搜)

    Problem Description You are given N sets.The i−th set has Ai numbers.You should divide the sets into ...

  9. hdu 4770(枚举 + dfs爆搜)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4770 思路:由于最多只有15个".",可以直接枚举放置的位置,然后判断是否能够全部 ...

随机推荐

  1. flask 的session

    python的flask操作设置.获得与删除session 首先讲一下Python的flask中session与cookies的关系,session是储存在服务器中的,cookies是储存在浏览器本地 ...

  2. unittest和pytest的区别

    一.用例编写规则 1.unittest提供了test cases.test suites.test fixtures.test runner相关的类,让测试更加明确.方便.可控.使用unittest编 ...

  3. java-web的mybatis的学习

    idea开发必须是把Mapper文件与配置文件放到Resources标记的classpath目录下,eclips好像放到哪都行指定好路径就可以了, maven里面做好配置resources的路径,不然 ...

  4. 纯Java增删改查

    //自己写的一个完整的带增删改查提交重置功能的表单代码.package com.l16.test5;import java.awt.Color;import java.awt.Container;im ...

  5. QQ项目(续)

    1.项目查找好友的原理 sql:select * from qquser where account in(select friendAccount from friend where userAcc ...

  6. Java笔记 #03# HtmlUnit爬虫

    存档留用 (= 存档留着备用) 爬的是一个开放的自动回复机器人 API 网站 http://i.itpk.cn/. 结构 大致如下: 我做的事情就是[输入文字,点击按钮,爬取内容],如上图所示. pa ...

  7. Spring Boot 2 (七):Spring Boot 如何解决项目启动时初始化资源

    Spring Boot 2 (七):Spring Boot 如何解决项目启动时初始化资源 在项目启动的时候需要做一些初始化的操作,比如初始化线程池,提前加载好加密证书等.今天就给大家介绍一个 Spri ...

  8. Linux Redhat 安装免费yum源

    Linux Redhat 安装免费yum源 出处地址:http://www.cnblogs.com/nbartchen/p/8565816.html 1.查看是否安装相关包 rpm -qa|grep ...

  9. 人机猜拳游戏Java

    作业要求: 我的代码: package day20181119;/** * 猜拳游戏 * @author Administrator * @version1.0 */import java.util. ...

  10. SSL及其加密通信过程

    SSL及其加密通信过程 什么是SSL SSL英文全称Secure Socket Layer,安全套接层,是一种为网络通信提供安全以及数据完整性的安全协议,它在传输层对网络进行加密.它主要是分为两层: ...