J-Beautiful Numbers

链接:https://www.nowcoder.com/acm/contest/163/J

来源:牛客网

时间限制:C/C++ 8秒,其他语言16秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

NIBGNAUK is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by the sum of its digits.

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

-->

示例1

输入

复制

2
10
18

输出

复制

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-模未知)的更多相关文章

  1. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

  2. 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 ...

  3. CodeForces - 55D - Beautiful numbers(数位DP,离散化)

    链接: https://vjudge.net/problem/CodeForces-55D 题意: Volodya is an odd boy and his taste is strange as ...

  4. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  5. cf55D. Beautiful numbers(数位dp)

    题意 题目链接 Sol 看到这种题就不难想到是数位dp了. 一个很显然的性质是一个数若能整除所有位数上的数,则一定能整除他们的lcm. 根据这个条件我们不难看出我们只需要记录每个数对所有数的lcm(也 ...

  6. Codeforces - 55D Beautiful numbers (数位dp+数论)

    题意:求[L,R](1<=L<=R<=9e18)区间中所有能被自己数位上的非零数整除的数的个数 分析:丛数据量可以分析出是用数位dp求解,区间个数可以转化为sum(R)-sum(L- ...

  7. CodeForces - 55D Beautiful numbers —— 数位DP

    题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds me ...

  8. CF55D Beautiful numbers (数位dp)

    题目链接 题解 一个数能被一些数整除,那么一定被这些数的\(lcm\)整除 那么我们容易想到根据\(lcm\)设状态 我们可以发现有用的\(lcm\)只有\(48\)个 那么按照一般的数位\(dp\) ...

  9. codeforces 55D. Beautiful numbers 数位dp

    题目链接 一个数, 他的所有位上的数都可以被这个数整除, 求出范围内满足条件的数的个数. dp[i][j][k], i表示第i位, j表示前几位的lcm是几, k表示这个数mod2520, 2520是 ...

  10. CF 55D. Beautiful numbers(数位DP)

    题目链接 这题,没想出来,根本没想到用最小公倍数来更新,一直想状态压缩,不过余数什么的根本存不下,看的von学长的blog,比着写了写,就是模版改改,不过状态转移构造不出,怎么着,都做不出来. #in ...

随机推荐

  1. 【C#图解】PictureBox.SizeMode 属性(转)

    PictureBoxSizeMode.Normal: 默认情况下,在 Normal 模式中,Image 置于 PictureBox 的左上角,凡是因过大而不适合 PictureBox 的任何图像部分都 ...

  2. 九度OJ 1021:统计字符 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5418 解决:3146 题目描述:     统计一个给定字符串中指定的字符出现的次数. 输入:     测试输入包含若干测试用例,每个测试用 ...

  3. python使用记录

    #2017-7-17 1.用len()函数可以获得list元素的个数; len()可以获取字符串长度 2. list正向0开始索引,,逆向-1开始索引; 也可以把元素插入到指定的位置,比如索引号为1的 ...

  4. CrystalReport runtime的下载地址

    SAP网站的东西实在太多了,找个CrytalReport都费劲.13.*版的可以通过下面的地址下载: SAP Crystal Reports, developer version for Micros ...

  5. python 搜集参数的共有项和所有项

    搜集共性项和所有项 ###搜集共有参数值 def intersect(*args): res=[] for x in args[0]: for other in args[1:]: if x not ...

  6. smartforms 二维码打印

    1. 安装TBarCode_SAPwin软件 1) 下载Barcode软件  下载TBarCode_SAPwin 软件.(如需生成SAP"字符控制序列"则需一并下载TBarCode ...

  7. mybatis中xml字段空判断及模糊查询

    由于业务特殊的查询需求,需要下面的这种查询,一直感觉模糊不清,本地测试一下顺便做个总结 贴一段xml代码,如下: <if test="receivedName != null and ...

  8. html5--2.4新的布局元素(3)-section

    html5--2.4新的布局元素(3)-section 学习要点 了解section元素的语义和用法 通过实例理解section元素的用法 article元素和section元素的区别和共同点 art ...

  9. Java se 知识图解

  10. js图片上传及显示

    html部分: <form action='' method='post' name='myform'> <input type='file' id='iptfileupload' ...