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 ...
随机推荐
- 【WinForm】创建自定义控件(转)
转自:http://www.cnblogs.com/bomo/archive/2012/12/09/2810559.html 虽然VS为我们提供了很多控件可以使用,但有时候这些控件仍然不能满足我们的要 ...
- 九度OJ 1017:还是畅通工程 (最小生成树)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4789 解决:2382 题目描述: 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府"畅通工程&quo ...
- 解决win7打印机共享出现“无法保存打印机设置(错误0x000006d9)的问题
最新解决win7打印机共享出现“无法保存打印机设置(错误0x000006d9)的问题,由系统下载吧率先分享: 有些用户在使用Windows7系统过程中,碰到到win7打印机共享出现“无法保存打印机设置 ...
- SQL2005数据库放在C盘,结果C盘满了,怎么搞到D盘
首先,你需要将自己所建立的数据库从SQL2005中分离出来,然后按照自己的存储路径找到自己所建数据库存储的位置,把它剪切到D盘就可以了.(mdf,ldf都应该考过去,自己建立路径存储就可以,再次打开的 ...
- JAVA Exception处理
原文地址:http://blog.csdn.net/hguisu/article/details/6155636 1. 引子 try…catch…finally恐怕是大家再熟悉不过的语句了,而且感觉用 ...
- 【linux】在linux挂在windows共享目录
mount -t cifs -o username=用户名,password='密码',vers=2.0 //windows共享目录 /linux挂载目录
- PAT 乙级 1081. 检查密码 (15) 【字符串】
题目链接 https://www.patest.cn/contests/pat-b-practise/1081 思路 有一个坑点 可能会输入空格 也就是说 要用 geline 或者 gets() 然后 ...
- 《C prime plus (第五版)》 ---第11章 字符串和字符串函数---2
11-3:字符串 输出 三个标准的函数:puts() fputs() printf() 1.puts()函数: #include<stdio.h> #define DEF "I ...
- easyui datagrid行合并
easyui datagrid行合并 合并方法 /** * EasyUI DataGrid根据字段动态合并单元格 * 参数 tableID 要合并table的id * 参数 colList 要合并的列 ...
- Android4.4 GPS框架分析【转】
本文转载自:http://blog.csdn.net/junzhang1122/article/details/46674569 GPS HAL层代码在目录trunk/Android/hardware ...