HDU4403(暴搜)
A very hard Aoshu problem
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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.
Input
Output
Sample Input
- 1212
- 12345666
- 1235
- END
Sample Output
- 2
- 2
- 0
- //2016.8.20
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #define N 20
- using namespace std;
- int ans, num[N][N], n;//num[i][j]用来记录从i到j位,数字的大小。
- char s[N];
- void dfsR(int pos, int leftsum, int rightsum)
- {
- if(pos == n && leftsum == rightsum){
- ans++; return;
- }
- if(leftsum < rightsum)return;//剪枝
- for(int i = pos; i < n; i++)
- dfsR(i+, leftsum, rightsum+num[pos][i]);
- }
- void dfsL(int pos, int sum, int mid)//pos表示当前处理的位置,sum表示已处理的和,mid表示等号的位置。
- {
- if(pos == mid)//对左边dfs完后,对右边dfs
- dfsR(mid, sum, );
- for(int i = pos; i < mid; i++)//枚举加号位置。
- dfsL(i+, sum+num[pos][i], mid);
- }
- int main()
- {
- while(scanf("%s", s)!=EOF)
- {
- if(s[] == 'E')break;
- ans = ;
- n = strlen(s);
- for(int i = ; i < n; i++)
- {
- int tmp = ;
- for(int j = i; j < n; j++)
- {
- tmp += s[j]-'';
- num[i][j] = tmp;
- tmp *= ;
- }
- }
- for(int i = ; i < n; i++)//枚举等号的位置,然后暴搜
- dfsL(, , i);
- cout<<ans<<endl;
- }
- return ;
- }
HDU4403(暴搜)的更多相关文章
- 【BZOJ-3033】太鼓达人 欧拉图 + 暴搜
3033: 太鼓达人 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 204 Solved: 154[Submit][Status][Discuss] ...
- c++20701除法(刘汝佳1、2册第七章,暴搜解决)
20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 输入正整数n,按从小到大的顺序输出所有 ...
- Codeforces Round #238 (Div. 2) D. Toy Sum 暴搜
题目链接: 题目 D. Toy Sum time limit per test:1 second memory limit per test:256 megabytes 问题描述 Little Chr ...
- poj 3080 Blue Jeans(水题 暴搜)
题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...
- Sicily1317-Sudoku-位运算暴搜
最终代码地址:https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1317.c 这题博主刷了1天,不是为了做出来,AC ...
- codeforces 339C Xenia and Weights(dp或暴搜)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Xenia and Weights Xenia has a set of weig ...
- Usaco 2.3 Zero Sums(回溯DFS)--暴搜
Zero SumConsider the sequence of digits from 1 through N (where N=9) in increasing order: 1 2 3 ... ...
- suoi62 网友跳 (暴搜+dp)
传送门 sbw太神啦orz 首先N<=20可以直接暴搜 然后玄学剪枝可以过18个点 那么N<=40的时候,就把它拆成两半分别暴搜,再用dp拼起来 对于前半段,设f[i][j]是开始高度为i ...
- bzoj1016/luogu4208 最小生成树计数 (kruskal+暴搜)
由于有相同权值的边不超过10条的限制,所以可以暴搜 先做一遍kruskal,记录下来每个权值的边使用的数量(可以离散化一下) 可以证明,对于每个权值,所有的最小生成树中选择的数量是一样的.而且它们连成 ...
随机推荐
- Java 8新特性探究(八)精简的JRE详解
http://www.importnew.com/14926.html 首页 所有文章 资讯 Web 架构 基础技术 书籍 教程 Java小组 工具资源 - 导航条 - 首页 所有文章 资讯 ...
- UWSGITOP-----监控uwsgi 性能
启动 uwsgi -x etc/bfdds_cookiemapping_conf.xml --stats /tmp/stats.socket 查看 uwsgitop /tmp/stats.socket ...
- 三种Dataase Mapping的系统架构
ORM - O/R M - Object/Relational Mapping: A technique/idea used to map objects and thier individual r ...
- Unity3d 开发之 ulua 坑的总结
相同的 lua 代码在安卓上能正常运行,但在 IOS 上可能不会正常运行而导致报红,崩溃等,我在使用 lua 编程时遇到的一些坑总结如下: 1. File.ReadAllText, 诸如以下代码在 i ...
- 如何在Eclipse中安装PDT插件来开发PHP
之前查过很多PDT的安装方法,60%都是让人直接安装All-in-one的PHP eclipse版本,纯属让人无语,而有些给出的PDT安装链接无法正确下载插件,对此,给出了我安装过的PDT插件下载地址 ...
- STM32驱动TEA5767收音机模块
Tea5767是飞利浦公司出的一款集成化的收音机芯片,大四的时候机缘巧合遇到了这个芯片,用了一下,写点资料 主要特性 TEA5767HN是一款低功耗立体声收音IC,广泛应用于手机MP3 .MP 4 播 ...
- iOS 获取本地文件的各种坑
1.无论:TXT,EPUB,PDF等各种格式的文件,保存到本地的时候,最好都保存成字母或者数字,不要保存成汉字,否则,在取文件的时候,由于编码的问题,各种瓦特 2.如果文件名真的保存成了汉字,那么进行 ...
- css(二) block,inline和inline-block概念和区别
转: http://www.cnblogs.com/KeithWang/p/3139517.html 总体概念 block和inline这两个概念是简略的说法,完整确切的说应该是 block-leve ...
- C#中BASE64和图片相互转换
//图片 转为 base64编码的文本 private void button1_Click(object sender, EventArgs e) { ...
- sql语句:if exists语句使用
') begin print('exists ') end else begin print('no exists ') end go