2020年Acm暑期考核Hznu _2797
题目链接:http://acm.hznu.edu.cn/OJ/problem.php?id=2797
题意:求1-N中有多少数字满足:
- x是正整数且无前导0。
- x(mod 666) = S(x)。
- 6在x这个数的各数位上出现的总次数必须为奇数。
题解:数位dp模板题(当时考核的时候忘记了板子当场去世)
Ac代码:
1 #include<iostream>
2 #include<algorithm>
3 #include<vector>
4 #include<cstring>
5 #include<cstdio>
6 using namespace std;
7 #define mem(s,n) memset(s,n,sizeof s);
8 #define ios {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); }
9 typedef long long ll;
10 const int maxn=5e6+1;
11 const int Inf=0x7f7f7f7f;
12 const ll Mod=1e9+7;
13 int dp[55][2][500][667];
14 string s;
15 int dfs(int now,int last,int sum,int mod,bool lim)//now表示当前位数,last=0表示前面有偶数个6,last=1表示前面有奇数个6,sum表示
16 { // 前几位数之和,mod表示对666取余后的数字,lim判断是否达到上界。
17 if(now==-1)
18 {
19 if(mod==sum&&(last&1)) return 1;
20 //last & 1 这个表达式可以用来判断last的奇偶性。二进制的末位为0表示偶数,最末位为1表示奇数
21 return 0;
22 }
23 if(!lim&&~dp[now][last&1][sum][mod]) return dp[now][last&1][sum][mod];
24 int up=lim?s[now]-'0':9;
25 ll ans=0;
26 for(int i=0;i<=up;i++)
27 {
28 ans+=dfs(now-1,last+(i==6),sum+i,(mod*10+i)%666,lim&&i==up);
29 ans%=Mod;
30 }
31 if(!lim) dp[now][last&1][sum][mod]=ans;
32 return ans;
33 }
34 int main()
35 {
36 int t;
37 scanf("%d",&t);
38 mem(dp,-1);
39 while(t--)
40 {
41 cin>>s;
42 reverse(s.begin(),s.end());//倒置函数因为要从最高位开始。
43 printf("%d\n",dfs(s.length()-1,0,0,0,1));
44 }
45 return 0;
46 }
2020年Acm暑期考核Hznu _2797的更多相关文章
- ACM暑期训练总结
ACM暑期集训总结报告 不知不觉,ACM暑期集训已经过去了一个月了(其实我还差几天才够一个月,因为最后几天要回家办助学贷款,所以没坚持到最后,当了个逃兵.....[汗])也到了结束的时候.在这一个月中 ...
- 中南大学2018年ACM暑期集训前期训练题集(入门题) X: 又一道简单题
简直智障,上一题V题,样例输出里面的“Case:”不要输出,到了这题又是要输出的了 #include<iostream> using namespace std; int num[1000 ...
- 中南大学2018年ACM暑期集训前期训练题集(入门题) Q: Simple Line Editor
数据有毒,一个一个读字符是错,整个字符串读入,一次就A了. 总之,数据总是没有错的,还是对c++了解地不够深刻,还有,在比赛中,一定要有勇气重构代码 错误代码: #include<iostrea ...
- 中南大学2018年ACM暑期集训前期训练题集(入门题) J : A Simple Problem
毒瘤哇!为什么要用long long 啊!!!这个题没有加法操作啊,为什么会爆int啊!!!! 思路: http://www.cnblogs.com/buerdepepeqi/p/9048130.ht ...
- 2156: 中南大学2018年ACM暑期集训前期训练题集(入门题) D: 机器人的指令
不要用gets!不要用gets!不要用gets! 不要用gets!不要用gets!不要用gets! 不要用gets!不要用gets!不要用gets! 不要用gets!不要用gets!不要用gets! ...
- 2017 ACM暑期多校联合训练 - Team 9 1008 HDU 6168 Numbers (模拟)
题目链接 Problem Description zk has n numbers a1,a2,...,an. For each (i,j) satisfying 1≤i<j≤n, zk gen ...
- 2017 ACM暑期多校联合训练 - Team 5 1008 HDU 6092 Rikka with Subset (找规律)
题目链接 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, s ...
- 2017 ACM暑期多校联合训练 - Team 4 1007 HDU 6073 Matching In Multiplication (模拟)
题目链接 Problem Description In the mathematical discipline of graph theory, a bipartite graph is a grap ...
- 2017 ACM暑期多校联合训练 - Team 4 1012 HDU 6078 Wavel Sequence (模拟)
题目链接 Problem Description Have you ever seen the wave? It's a wonderful view of nature. Little Q is a ...
随机推荐
- DOM型XSS
打开漏洞页面,随便输入点东西,发现没有啥东西. 但是我们发现我们输入的11,在面的herf 中 看到这儿就很简单了,我们只需要闭合一下,就可以构造出我们的payload了. '><img ...
- openssl的用法
Openssl详细用法: OpenSSL 是一个开源项目,其组成主要包括一下三个组件: openssl:多用途的命令行工具 libcrypto:加密算法库 libssl:加密模块应用库,实现了ssl及 ...
- Error: Cannot find module 'koa-router'
Error: Cannot find module 'koa-router' koa-router !== koa-route # install OK $ yarn add koa-router h ...
- cnblogs 日期错乱 bug
cnblogs 日期错乱 bug 时间错乱 bug archive/2004/01/13/ 什么鬼 呀默认时间戳 https://www.cnblogs.com/xgqfrms/archive/200 ...
- Python Tutorials
Python Tutorials Real Python https://realpython.com/ https://realpython.com/courses/ https://realpyt ...
- How to get a DOM element's ::before content with JavaScript?
How to get a DOM element's ::before content with JavaScript? https://stackoverflow.com/questions/443 ...
- Flutter Widget API
Flutter Widget API https://api.flutter.dev/ https://api.flutter.dev/flutter/material/material-librar ...
- NGK生态之星空计划启动在即,稀有VAST高兑换比带来高价值!
NGK生态之星空计划启动在即,为了感谢NGK布道者的支持,NGK官方将全力辅助算力市场,开展全新的星空计划,并发行星空币SPC,空投给算力持有者进行额外奖励. 至此,SPC已经顺利完成2轮空投,也初步 ...
- Linux零拷贝技术
本文转载自Linux零拷贝技术 导语 本文讲解 Linux 的零拷贝技术,云计算是一门很庞大的技术学科,融合了很多技术,Linux 算是比较基础的技术,所以,学好 Linux 对于云计算的学习会有比较 ...
- GET和POST两者的区别
GET 和 POST 是 HTTP 协议中的两种发送请求的基本方法,对于前端开发者而言,几乎每天都在使用它们,再熟悉不过了,一般也都能说出几点两者的区别. 如果面试中被问到这个问题,先回答一下几点,肯 ...