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的更多相关文章

  1. BNUOJ 52325 Increasing or Decreasing 数位dp

    传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...

  2. UVALive - 6575 Odd and Even Zeroes 数位dp+找规律

    题目链接: http://acm.hust.edu.cn/vjudge/problem/48419 Odd and Even Zeroes Time Limit: 3000MS 问题描述 In mat ...

  3. UVALive - 6872 Restaurant Ratings 数位dp

    题目链接: http://acm.hust.edu.cn/vjudge/problem/113727 Restaurant Ratings Time Limit: 3000MS 题意 给你一个长度为n ...

  4. 浅谈数位DP

    在了解数位dp之前,先来看一个问题: 例1.求a~b中不包含49的数的个数. 0 < a.b < 2*10^9 注意到n的数据范围非常大,暴力求解是不可能的,考虑dp,如果直接记录下数字, ...

  5. codeforces Hill Number 数位dp

    http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits:  5000 MS   Memory Limits: ...

  6. SRM 510 2 250TheAlmostLuckyNumbersDivTwo(数位dp)

    SRM 510 2 250TheAlmostLuckyNumbersDivTwo Problem Statement John and Brus believe that the digits 4 a ...

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

  8. HDU(4734),数位DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4734 F(x) Time Limit: 1000/500 MS (Java/Others) ...

  9. hdu----(5045)Contest(数位dp)

    Contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

随机推荐

  1. XtraEditors五、SpinEdit、TimeEdit

    SpinEdit控件 此按钮控件是用来增加或减少在编辑的文本编辑区显示的数值, 该编辑值可以是一个整数或浮点数. 其 Text属性 用于设置编辑区的文本: 其 Value属性 用于获取编辑区的值: 示 ...

  2. 阿里八八Alpha阶段Scrum(5/12)

    今日进度 叶文滔: 与添加日程界面完成界面对接. 问题困难:发现浮动按钮拖曳存在BUG,无法正确判断拖曳与点击事件,已经修复为普通悬浮按钮. 林炜鸿: 绘制完成添加日程界面. 李嘉群: 1.尝试有关用 ...

  3. 《深入理解JVM》读书笔记

    目前只是整理了书的前几章,把jvm的内存划分简要说明.垃圾回收算法.垃圾回收器.常用的命令和工具进行说明.命令和工具的使用找个时间需要详细按步骤截图说明. 还有一部分内容是举例说明了一下字节码指令的样 ...

  4. Perl 杂记

    1. Perl 变量: 创建变量是以 $ 开头,比如定义一个变量: $val = "Good job !" 2. Perl 控制流 if 语法: if ( ) {  },注意if ...

  5. Python2.7-matplotlib

    matplotlib的pyplot子库提供了和matlab类似的绘图API,方便用户快速绘制2D图表 一般用以下形式导入:import matplotlib.pyplot as plt 一般用法:1. ...

  6. nginx反向代理 强制https请求 + 非root用户起80,443端口

    1. #强制使用https跳转 return 301 https://$server_name$request_uri;rewrite ^(.*)$ https://${server_name}$1 ...

  7. FFMpeg笔记(七) 代码结构分析,以HLS为例

    HLS流在播放时是先解协议(hls.c)后解封装(mpegts.c),libavformat下的hls.c和mpegts.c实际上是同一个级别的,同属于demuxer. 一.解HLS协议 1. FFm ...

  8. NSDictionary实现原理-ios哈希hash和isEqual

    NSDictionary实现原理-ios哈希hash和isEqual   OC中自定义类的NSCopying实现的注意事项(isEqual & hash实现) http://blog.csdn ...

  9. DB2创建function(二)

    DB2创建function(一),介绍将function内容作为字段值,或做为一个where条件的情况. DB2创建function(二),介绍返回的内容为一个集合的情况.调用结果集的示例如下: se ...

  10. jquery方法简单记录

      append() - 在被选元素的结尾插入内容 prepend() - 在被选元素的开头插入内容 after() - 在被选元素之后插入内容 before() - 在被选元素之前插入内容 firs ...