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 ...
随机推荐
- 深入浅出Windows命令——telnet
- word文档重新打开后文档结构错乱
word文档重新打开后文档结构错乱,然后通过如下方法解决了. OFFICE2007及以上. 在打开word的时候左下角会有提示word自动更新文档样式,按esc键取消,然后在大纲模式下任 ...
- November 03rd, 2017 Week 44th Friday
The secret of success is to do the common things uncommonly well. 成功的秘诀就是把平凡的事情做得异常的好. Sometimes you ...
- BZOJ3105:[CQOI2013]新Nim游戏(线性基,贪心)
Description 传统的Nim游戏是这样的:有一些火柴堆,每堆都有若干根火柴(不同堆的火柴数量可以不同).两个游戏者轮流操作,每次可以选一个火柴堆拿走若干根火柴.可以只拿一根,也可以拿走整堆火柴 ...
- C#游戏开发中快速的游戏循环
C#游戏开发中快速的游戏循环的实现.参考<精通C#游戏编程>一书. using System; using System.Collections.Generic; using System ...
- 使用级联分类器实现人脸检测(OpenCV自带的数据)
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...
- 如何为Windows Forms应用程序添加启动参数(Start-Up Parameters)
很多场合下,我们需要通过命令行或者快捷方式在Windows Forms程序启动时向其传递参数. 这些参数可能是用来加载某一个文档,或者是应用程序的初始化配置文件. 特别是对那些需要高度自定义配置的大程 ...
- 将myeclipse中不适用的插件禁用掉
转载地址http://blog.csdn.net/yuanboitliuyuan/article/details/7360553 去掉启动时不用的插件启动: 操作方法: windows->pre ...
- mysql数据库怎么存入emoji表情,更改utf8mb4后为什么出现全是问号
在项目中遇到有人存emoji表情,出现如下错误: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\x94' for colum ...
- 基于Azure的软件部署和开发系列沙龙
活动简介: Azure是一种灵活和支持互操作的平台,它可以被用来创建云中运行的应用或者通过基于云的特性来加强现有应用.它开放式的架构给开发者提供了Web应用.互联设备的应用.个人电脑.服务器.或者提供 ...