HUST 1599 - Multiple(动态规划)
1599 - Multiple
时间限制:2秒 内存限制:64兆
461 次提交 111 次通过
题目描述
Rocket323 loves math very much. One day, Rocket323 got a number string. He could choose some consecutive digits from the string to form a number. Rocket323 loves 64 very much, so he wanted to know how many ways can he choose from the string so the number he got multiples of 64 ?
A number cannot have leading zeros. For example, 0, 64, 6464, 128 are numbers which multiple of 64 , but 12, 064, 00, 1234 are not.
输入
Multiple cases, in each test cases there is only one line consist a number string.
Length of the string is less than 3 * 10^5 .
Huge Input , scanf is recommended.
输出
Print the number of ways Rocket323 can choose some consecutive digits to form a number which multiples of 64.
样例输入
64064
样例输出
5
提示
There are five substrings which multiples of 64.
[64]064
640[64]
64[0]64
[64064]
[640]64
来源
Problem Setter : Yang Xiao
思路:
根据同余定理,每次枚举到一个数,都把前面的存在的余数乘以10加上这个数再对64取余,就产生新的余数,最后统计余数是0的个数有多少
#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
char a[300005];
long long int dp[2][65];
long long int tag[65];
long long int ans;
long long int res;
int now;
int main()
{
while(scanf("%s",a)!=EOF)
{
ans=0;res=0;
int len=strlen(a);
memset(dp,0,sizeof(dp));
now=0;
for(int i=0;i<len;i++)
{
for(int j=63;j>=0;j--)
dp[now^1][j]=0;
for(int j=63;j>=0;j--)
{
int num=(j*10+a[i]-'0'+64)%64;
dp[now^1][num]+=dp[now][j];
}
if(a[i]!='0')
dp[now^1][a[i]-'0']++;
else
ans++;
res+=dp[now^1][0];
now^=1;
}
printf("%lld\n",res+ans);
}
return 0;
}
HUST 1599 - Multiple(动态规划)的更多相关文章
- HUST - 1599 Multiple
input 长度不大于3*10e5的数字串 output 不含前导0的能整除64的字串的个数(0算一个,064不算) 一般数组中找能整除一个数的字串都是用取余来做的 用一个a[64]来存下从1-i位累 ...
- POJ 3659 Cell Phone Network / HUST 1036 Cell Phone Network(最小支配集,树型动态规划,贪心)-动态规划做法
POJ 3659 Cell Phone Network / HUST 1036 Cell Phone Network(最小支配集,树型动态规划,贪心) Description Farmer John ...
- ACM学习历程—HDU 3092 Least common multiple(数论 && 动态规划 && 大数)
Description Partychen like to do mathematical problems. One day, when he was doing on a least common ...
- [leetcode] 题型整理之动态规划
动态规划属于技巧性比较强的题目,如果看到过原题的话,对解题很有帮助 55. Jump Game Given an array of non-negative integers, you are ini ...
- [ACM_动态规划] 轮廓线动态规划——铺放骨牌(状态压缩1)
Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, af ...
- hdu 1087 动态规划之最长上升子序列
http://acm.hdu.edu.cn/showproblem.php?pid=1087 Online Judge Online Exercise Online Teaching Online C ...
- POJ 1426 Find The Multiple --- BFS || DFS
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...
- poj 动态规划题目列表及总结
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
- poj动态规划列表
[1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...
随机推荐
- SQL Compare数据库比较工具 完全破解+使用教程
来源http://www.cnblogs.com/duci/articles/4482665.html 一.使用教程 SQL Compare是编程人员常用的比较两个数据库之间差异的工具.可以用来比较数 ...
- 解决 iOS7 通过tag 找不到 UITableViewCell 的子控件(转)
转自:http://www.cnblogs.com/waiwaibuzhidao/p/3340400.html 当iOS7问世,程序的世界就混乱了,以前良好的程序,现在是一塌糊涂,于是只能把问题一个一 ...
- AngularJS------命令行
如下:(‘$’符号不需要输入哦) $ ng build --发布项目
- Ulua_toLua_基本案例(六)_LuaCoroutine2
Ulua_toLua_基本案例(六)_LuaCoroutine2 using UnityEngine; using System.Collections; using LuaInterface; pu ...
- 判断元素是否存时,使用isset会比in_array快得多
情境 有时候,我们需要判断一个元素是否存在于已有数据中(以此来获得非重复值),这时候,使用isset来判断会比in_array快得多很多!! 测试 1)准备测试数据 $exists_a = []; $ ...
- java serialize 浅谈
对象的串行化(Serialization) 一.串行化的概念和目的 1.什么是串行化 对象的寿命通常随着生成该对象的程序的终止而终止.有时候,可能需要将对象的状态保存下来,在需要时再将对象恢复.我们把 ...
- Windows命令行参数的知识(一)
最近没事的时候,准备研究一下Windows命令行参数的知识,因为每次自己在操作电脑时总是效率太慢,如果能够了解Windows参数的一些知识,绝对能提高效率! 基本外部命令和内部命令 首先是基本的知识, ...
- nginx fastcgi.conf的参数
编写FastCGI程序的时候有很多像php一样的参数可以获取到,并利用起来,下面就是FastCGI的一些参数. fastcgi_param SCRIPT_FILENAME $do ...
- js元素闪动效果
<img src="http://yjy.allbring.com/UpLoadFiles/head/p1_20140326104945_17-10164142709.jpg" ...
- C# 泛型的简单讲解和应用
泛型 什么是泛型 泛型是 2.0 版 C# 语言和公共语言运行库 (CLR) 中的一个新功能.泛型将类型参数的概念引入 .NET Framework,类型参数使得设计如下类和方法成为可能:这些类和方法 ...