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. VC调用Delphi DLL

    别的没什么,是一定可以调用成功的.但是意外的是,ShowMessage函数在DLL里也可以轻易被调用.此外,Delphi里的var 相当于VC里的引用,需要在函数原型里正确标识,否则传递普通变量甚至常 ...

  2. SAP-Function_01

    TH_POPUP –在特定用户屏幕上显示一个系统消息 1 . 函数WS_UPLOAD     功能﹕将TXT文件转换成SAP中的内表定义的数据表格文件    注意﹕1 函数将按参数 data_tab  ...

  3. Web框架和Django基础

    核心知识点 1.web应用类似于一个socket客户端,用来接收请求 2.HTTP:规定了客户端和服务器之间的通信格式. 3.一个HTTP包含两部分,header和body,body是可选,\r\n分 ...

  4. perl之创建临时文件夹遇到同名文件该咋办

    当你在目录下进行一系列操作时,若要创建许多文件或者修改文件,可能会遇到许多麻烦的事.所以呢,新建一个文件夹,然后在这个文件夹下新建文件或者修改文件.假设,你的代码要在一个目录下新建一个文件夹,名为Tm ...

  5. 用户态文件系统fuse学习【转】

    本文转载自:https://blog.csdn.net/ty_laurel/article/details/51685193 FUSE概述 FUSE(用户态文件系统)是一个实现在用户空间的文件系统框架 ...

  6. 吴恩达机器学习笔记(十二) —— Application Example: Photo OCR(完)

    主要内容: 一.Photo OCR 二.Getting lots of data:artificial data synthesis 三.Ceiling analysis 一.Photo OCR Ph ...

  7. python的tkinter对话框

    import tkinter.messagebox #这个是消息框,对话框的关键 root = tkinter.Tk() root.withdraw() a=tkinter.messagebox.sh ...

  8. codeforces 703B B. Mishka and trip(数学)

    题目链接: B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input stan ...

  9. Python 微信通知 先挖个坑

    桑心病狂,试试把报警信息发到微信上 原文  https://segmentfault.com/a/1190000009717078  

  10. OpenCV——PS滤镜算法之Spherize 球面化(凸出效果)

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...