2018上海大都会 J-Beautiful Numbers(数位dp-模未知)
J-Beautiful Numbers
链接:https://www.nowcoder.com/acm/contest/163/J
来源:牛客网
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
We will not argue with this and just count the quantity of beautiful numbers from 1 to N.
输入描述:
The first line of the input is T(1≤ T ≤ 100), which stands for the number of test cases you need to solve.
Each test case contains a line with a positive integer N (1 ≤ N ≤ 10
12
).
输出描述:
For each test case, print the case number and the quantity of beautiful numbers in [1, N].
输入例子:
2
10
18
输出例子:
Case 1: 10
Case 2: 12
-->
输出
Case 1: 10
Case 2: 12 对于模未知的数位dp,暴力枚举模即可。
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#define MAX 13
#define INF 0x3f3f3f3f
using namespace std; typedef long long ll; int a[MAX];
int poss,MOD;
ll dp[MAX][][][];
ll dfs(int pos,ll sta,int sum,bool limit){
int i;
if(pos==-) return sum==MOD&&sta==;
if(!limit&&dp[pos][sta][sum][MOD]!=-) return dp[pos][sta][sum][MOD];
int up=limit?a[pos]:;
ll cnt=;
for(i=;i<=up;i++){
cnt+=dfs(pos-,(sta*+i)%MOD,sum+i,limit&&i==a[pos]);
}
if(!limit) dp[pos][sta][sum][MOD]=cnt;
return cnt;
}
ll solve(ll x){
int pos=;
while(x){
a[pos++]=x%;
x/=;
}
poss=pos-;
ll ans=;
for(MOD=;MOD<=;MOD++){
ans+=dfs(pos-,,,true);
}
return ans;
}
int main()
{
int t,tt=;
ll r;
scanf("%d",&t);
memset(dp,-,sizeof(dp));
while(t--){
scanf("%lld",&r);
printf("Case %d: %lld\n",++tt,solve(r));
}
return ;
}
2018上海大都会 J-Beautiful Numbers(数位dp-模未知)的更多相关文章
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
- Codeforces Beta Round #51 D. Beautiful numbers 数位dp
D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...
- CodeForces - 55D - Beautiful numbers(数位DP,离散化)
链接: https://vjudge.net/problem/CodeForces-55D 题意: Volodya is an odd boy and his taste is strange as ...
- codeforces 55D - Beautiful numbers(数位DP+离散化)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- cf55D. Beautiful numbers(数位dp)
题意 题目链接 Sol 看到这种题就不难想到是数位dp了. 一个很显然的性质是一个数若能整除所有位数上的数,则一定能整除他们的lcm. 根据这个条件我们不难看出我们只需要记录每个数对所有数的lcm(也 ...
- Codeforces - 55D Beautiful numbers (数位dp+数论)
题意:求[L,R](1<=L<=R<=9e18)区间中所有能被自己数位上的非零数整除的数的个数 分析:丛数据量可以分析出是用数位dp求解,区间个数可以转化为sum(R)-sum(L- ...
- CodeForces - 55D Beautiful numbers —— 数位DP
题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds me ...
- CF55D Beautiful numbers (数位dp)
题目链接 题解 一个数能被一些数整除,那么一定被这些数的\(lcm\)整除 那么我们容易想到根据\(lcm\)设状态 我们可以发现有用的\(lcm\)只有\(48\)个 那么按照一般的数位\(dp\) ...
- codeforces 55D. Beautiful numbers 数位dp
题目链接 一个数, 他的所有位上的数都可以被这个数整除, 求出范围内满足条件的数的个数. dp[i][j][k], i表示第i位, j表示前几位的lcm是几, k表示这个数mod2520, 2520是 ...
- CF 55D. Beautiful numbers(数位DP)
题目链接 这题,没想出来,根本没想到用最小公倍数来更新,一直想状态压缩,不过余数什么的根本存不下,看的von学长的blog,比着写了写,就是模版改改,不过状态转移构造不出,怎么着,都做不出来. #in ...
随机推荐
- SpringMVC @ResponseBody和@RequestBody使用
@ResponseBody用法 作用: 该注解用于将Controller的方法返回的对象,根据HTTP Request Header的Accept的内容,通过适当的HttpMessageConvert ...
- 高德地图API开发二三事(一)如何判断点是否在折线上及引申思考
最近使用高德地图 JavaScript API 开发地图应用,提炼了不少心得,故写点博文,做个系列总结一下,希望能帮助到LBS开发同胞们. 项目客户端使用高德地图 JavaScript API,主要业 ...
- mooc课程mit 6.00.1x--problem set3解决方法
RADIATION EXPOSURE 挺简单的一道题,计算函数和算法过程都已经给出,做一个迭代计算就行了. def radiationExposure(start, stop, step): ''' ...
- Flask:程序结构
在Flask中需要配置各种各样的参数.比如设置秘钥,比如上一章介绍到的配置数据库类型. app.config['SECRET_KEY']=os.urandom(20) app.config['SQLA ...
- 一文读懂实用拜占庭容错(PBFT)算法
在区块链中有一个著名的问题,就是拜占庭将军问题,对于拜占庭将军问题,网上的文章已经多得不要不要了,今天和大家分享的是其相关的实用拜占庭容错算法,一起来看看吧. 实用拜占庭容错算法(Practi ...
- (*)(转)要快速学习SSM框架,你需要一套学习曲线平滑的教程
作者:meepo链接:https://www.zhihu.com/question/57719761/answer/156952139来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...
- NET LOCALGROUP命令详解(将用户添加到管理员组等)
NET LOCALGROUP [groupname [/COMMENT:"text"]] [/DOMAIN] groupname {/ADD [/COMMENT:"tex ...
- Contiki Ctimer模块
Ctimer 提供和Etimer类似的功能,只是Ctimer是在一段时间后调用回调函数,没有和特定进程相关联. 而Etimer是在一段时间后发送PROCESS_EVENT_TIMER事件给特定的进程. ...
- ORA-00600: internal error code, arguments: [6749], [3], [12602196]
环境信息:Linux5.8 oracle10.2.0.4 问题现象: 现象1:alert日志有大量下面的错误信息: Wed Aug 27 21:01:27 2014Errors in file /u0 ...
- Linux下查看端口占用情况
用启动服务的账号登录,然后运行命令: lsof -i:<端口号> 也可使用命令: netstat -apn|grep <端口号> 找到进程号以后,再使用以下命令查看详细信息: ...