HUST 1599 - Multiple(动态规划)
来源:互联网 发布:炒股必备软件 编辑:程序博客网 时间:2024/06/01 07:48
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
- [HDOJ 4913] Least common multiple [动态规划+线段树]
- POJ3781-3786(Unknown Summer Training ID 8911 0x03 on hust oj)(枚举、贪心、动态规划)
- hust 华中科技大学校赛初赛 1599 Multiple 字符串中64的倍数的个数
- 动态规划!!!动态规划!!!
- HUST
- HUST
- HUST
- HUST
- HUST 1599 (找规律)
- 动态规划
- 动态规划
- 动态规划
- 动态规划
- 动态规划
- 动态规划
- 动态规划
- 日志记录—Java中的日志——Java.util.logging、log4j、commons-logging
- Java反射机制的学习
- WebPack系列教程(二):动机
- vitrual与类的大小
- 天声人語 20160309 女性が働きやすい社会へ
- HUST 1599 - Multiple(动态规划)
- Spark读取数据库(Mysql)的四种方式讲解
- 2015年大二上-数据结构-查找-2-(2)-用哈希法组织关键字
- 日经春秋 20160309
- MC9S12G128 IOC(输入捕获)配置
- 不通过反射在其它类中直接调用access$000方法,即:如何绕过这个检查
- win10关机声音自定义教程
- python open mode取值组合
- 初学HTML5、初入前端