UVALive 4877 Non-Decreasing Digits 数位DP
4877 Non-Decreasing Digits
A number is said to be made up ofnon-decreasing digitsif all the digits to theleftof any digit is lessthan or equal to that digit. For example, the four-digit number 1234 is composed of digits that arenon-decreasing. Some other four-digit numbers that are composed of non-decreasingdigits are 0011, 1111,1112, 1122, 2223. As it turns out, there are exactly 715 four-digit numbers composed of non-decreasingdigits.Notice that leading zeroes are required: 0000, 0001, 0002 are all valid four-digit numbers withnon-decreasingdigits.For this problem, you will write a program that determines how many such numbers there are witha specified number of digits.
Input
The first line of input contains a single integerP(1P1000), which is the number of data sets thatfollow. Each data set is a single line that contains the data set number, followed by a space, followedby a decimal integer giving the number of digitsN(1N64).
Output
For each data set there is one line of output. It contains the data set number followed by a single space,followed by the number of N digit values that are composed entirely ofnon-decreasingdigits.
Sample Input
3
1 2
2 3
3 4
Sample Output
1 55
2 220
3 715
题目意思:求n位非递减数列的个数,可以有相同的数。
解题思路:数位DP,dp[i][j]表示i位,最高位是j的符合题意的个数。
之前博客参考 :https://www.cnblogs.com/wkfvawl/p/9438921.html
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long int
using namespace std;
ll dp[][];
void DPlist()
{
ll i,j,k;
memset(dp,,sizeof());
for(i=;i<=;i++)
{
dp[][i]=;
}
for(i=;i<=;i++)///dp[i][j]表示i位,最高位是j的符合题意的个数
{
for(j=;j<=;j++)
{
for(k=;k<=j;k++)///把上一个位数小于等于j的dp全加起来
{
dp[i+][j]+=dp[i][k];
}
}
dp[i][]=;///用来存总和
for(j=;j<=;j++)
{
dp[i][]+=dp[i][j];
}
}
}
int main()
{
ll t,e,n,i;
scanf("%d",&t);
DPlist();
while(t--)
{
scanf("%lld%lld",&e,&n);
printf("%lld %lld\n",e,dp[n][]);
}
}
UVALive 4877 Non-Decreasing Digits 数位DP的更多相关文章
- BNUOJ 52325 Increasing or Decreasing 数位dp
传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...
- UVALive - 6575 Odd and Even Zeroes 数位dp+找规律
题目链接: http://acm.hust.edu.cn/vjudge/problem/48419 Odd and Even Zeroes Time Limit: 3000MS 问题描述 In mat ...
- UVALive - 6872 Restaurant Ratings 数位dp
题目链接: http://acm.hust.edu.cn/vjudge/problem/113727 Restaurant Ratings Time Limit: 3000MS 题意 给你一个长度为n ...
- 浅谈数位DP
在了解数位dp之前,先来看一个问题: 例1.求a~b中不包含49的数的个数. 0 < a.b < 2*10^9 注意到n的数据范围非常大,暴力求解是不可能的,考虑dp,如果直接记录下数字, ...
- codeforces Hill Number 数位dp
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits: 5000 MS Memory Limits: ...
- SRM 510 2 250TheAlmostLuckyNumbersDivTwo(数位dp)
SRM 510 2 250TheAlmostLuckyNumbersDivTwo Problem Statement John and Brus believe that the digits 4 a ...
- HDU 5787 K-wolf Number 数位DP
K-wolf Number Problem Description Alice thinks an integer x is a K-wolf number, if every K adjacen ...
- HDU(4734),数位DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4734 F(x) Time Limit: 1000/500 MS (Java/Others) ...
- hdu----(5045)Contest(数位dp)
Contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
随机推荐
- 团队作业——Beta冲刺3
团队作业--Beta冲刺 冲刺任务安排 杨光海天 今日任务:浏览详情界面的开发 明日任务:浏览详情界面的开发 吴松青 今日任务:与队长一同进行图片详情的开发,接触了一些自己没接触过的知识点并向队友学习 ...
- 【Ansible 文档】【译文】常见问题
http://docs.ansible.com/ansible/latest/faq.html 如何为一个task或者整个Playbook设置PATH或者任意其他环境变量? 通过environment ...
- [部署]VM11下CentOS7mini安装及配置
最近使用了CentOS发现比Ubuntu更简洁,有些爱上CentOS了 1. 准备一版CentOS安装镜像文件 官网下载地址:http://www.centos.org/download/ 官方有三个 ...
- 关于flex的crossdomain.xml文件存放目录
最近在项目中遇到flex跨域访问的安全沙箱问题,查资料了解到需要在服务端加上crossdomain.xml文件,即: <?xml version="1.0" encoding ...
- python第四十一课——析构函数
3.析构函数 格式:__del__(self): 作用: 在程序结束前将对象回收,释放资源的行为 演示析构函数的使用: class Animal: #定义构造函数 def __init__(self, ...
- 1008. [HNOI2008]越狱【快速幂】
Description 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种.如果 相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱 I ...
- App常见产品问题及预防方法
01界面适配 a:手机分辨率为1920x7080的高分辨率手机,在调整手机字体大小时,会导致页面显示出现变形: b:因用户设置的特殊字体导致列表的字母条不显示: c:某些banner 图片在部分机型只 ...
- Python2.7-sched
sched 模块,实现了简单的事件按计划时间表执行的功能,缺点在于运行的时候会占用主线程,直到事件执行完毕,更好的方法是用 threading.Timer 类 创建实例方法: sched.schedu ...
- threedLocal设计原因及详解
ThreedLocal在中文的翻译中应该翻译成:线程局部变量. 1:设计的原因 在并发编程的时候,成员变量如果不做任何处理其实是线程不安全的,各个线程都在操作同一个变量,显然是不行的,并且我们也知道v ...
- 【转】软件质量之道:SourceMonitor
转:https://blog.csdn.net/feng_ma_niu/article/details/40594799 SourceMonitor是一个源代码衡量工具,由http://www.cam ...