【HDOJ】4403 A very hard Aoshu problem
HASH+暴力。
/* 4403 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
using namespace std; #define MAXN 55 map<int, int> tb[];
char s[MAXN]; int get(int b, int e) {
int ret = ; for (int i=b; i<e; ++i)
ret = *ret + s[i] - ''; return ret;
} void myfill(int b, int e, int v, int in) {
int tmp = ; if (b == e)
tb[in][v]++; for (int i=b; i<e; ++i) {
tmp = * tmp + s[i] - '';
myfill(i+, e, v+tmp, in);
}
} int main() {
int len;
int i, j, k, tmp;
int x, y;
int ans; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif while (scanf("%s", s)!=EOF && s[]!='E') {
len = strlen(s);
ans = ;
for (i=; i<len; ++i) {
tb[].clear();
tb[].clear();
myfill(, i, , );
myfill(i, len, , );
for (map<int, int>::iterator iter=tb[].begin(); iter!=tb[].end(); iter++)
ans += iter->second * tb[][iter->first];
}
printf("%d\n", ans);
} return ;
}
【HDOJ】4403 A very hard Aoshu problem的更多相关文章
- 【HDOJ】3509 Buge's Fibonacci Number Problem
快速矩阵幂,系数矩阵由多个二项分布组成.第1列是(0,(a+b)^k)第2列是(0,(a+b)^(k-1),0)第3列是(0,(a+b)^(k-2),0,0)以此类推. /* 3509 */ #inc ...
- 【HDOJ】4972 A simple dynamic programming problem
水题. #include <cstdio> #include <cstring> #include <cstdlib> int abs(int x) { ? -x: ...
- 【数论】FOJ 2238 Daxia & Wzc's problem
题目链接: http://acm.fzu.edu.cn/problem.php?pid=2238 题目大意: 已知等差数列A(0)的首项a和公差d,求出数列A(0)前n项和,得到新数列A(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 ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
随机推荐
- java中的String.format使用
format(String format, Objece... argues)函数相当于C语言中的printf函数,但是相对来说更灵活. 和C中的printf函数差不多,在fo ...
- Qt Quick 事件处理之信号与槽
前面两篇文章<QML 语言基础>和<Qt Quick 简单教程>中我们介绍了 QML 语言的基本的语法和 Qt Quick 的常见元素,亲们,通过这两篇文章,您应该已经能够完毕 ...
- @property的特性
@property还有一些关键字,它们都是有特殊作用的,比如上述代码中的nonatomic,strong: 1 2 @property(nonatomic,strong) NSString *carN ...
- [Javascript] Logging Pretty-Printing Tabular Data to the Console
Learn how to use console.table to render arrays and objects in a tabular format for easy scanning ov ...
- 【C语言天天练(二一)】内联函数
引言:调用函数时,一般会由于建立调用.传递參数.跳转到函数代码并返回等花费掉一些时间,C语言的解决的方法是使用类函数宏.在C99中,还提出了第二种方法:内联函数. 内联 ...
- 根据IP地址获取IP的详细信息
<?php header('Content-Type:text/html; charset=utf-8'); function ip_data() { $ip = GetIP(); $url = ...
- Macos Coco2d-x Android开发
1. 在装好环境 2. cocos new [-h] [-p PACKAGE_NAME] -l {cpp,lua,js} [-d DIRECTORY] [-t TEMPLATE_NAME] [--io ...
- C/C++笔试题整理
1. C的结构体和C++结构体的区别 (1)C的结构体内不允许有函数存在,C++允许有内部成员函数,且允许该函数是虚函数.所以C的结构体是没有构造函数.析构函数.和this指针的. (2)C的结构体对 ...
- LeanCloud使用入门(android)
LeanCloud算是一个简单易用的云服务器,其中包含了强大的数据库支持,我们只需要将此服务器应用到本地的代码即可实现后台的存储与交互. 那么,如何简单实现本地代码和LeanCloud服务器的交互呢? ...
- Camera类
Camera类 使用 Camera 类可从连接到运行 Flash Player 的计算机的摄像头中 捕获视频. 使用 Video 类可在本地监视视频. 使用 NetConnection 和 NetS ...