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 ...
随机推荐
- 安装composer出现链接补上的问题
下载 Composer-Setup.exe 后安装出错: Composer Download Error Connection Error [ERR_CONNECTION]: Unable to co ...
- DevExpress05、TileControl、AlertControl
TileControl控件 该控件是根据Windows 8的用户界面设计的,可以轻松地把各个控制块集成到窗体上. 1. IndertBetweenGroups属性 控制两个Group之间的间距: ...
- 阿里八八Alpha阶段Scrum(4/12)
今日进度 叶文滔: 整合了一下已完成的界面设计,修复了一些BUG. 问题困难:制作多级悬浮按钮阻碍重重,首先是刚更新不久的Andriod Studio 3.0向前兼容性差,一些语句规则的修改无所适从, ...
- bat脚本,备份数据库并压缩
forfiles /p "D:\DBBackup" /m "*.sql" /d -08 /c "cmd /c del @path"forfi ...
- 更改Apache默认起始(索引)页面:DirectoryIndex
Apache默认索引页面是index.html,修改成其他文件需要修改httpd.conf文件: # # DirectoryIndex: sets the file that Apache will ...
- h5实现手机端等级进度条
h5实现等级进度条 需求如下: 实现一个动画进度条,页面一打开实现一个进度条动画,因为App这个页面会经常改,所以没有使用原审Android或者IOS来实现,希望通过H5来做: 服务器端返回如下数据: ...
- day39
今日内容: 1.对于表,库,记录的基本操作 2.数据库引擎的了解 3.表的详细 4.数据类型的掌握 1.回顾昨日对于表,库,记录的基本操作 库 增: create database mydb2; 删: ...
- java进阶的书籍
通过观看职话大数据论坛,了解到华信智原.项目总监就为我们推荐了一些JAVA程序员必看的书籍,使我们在学习过程中可以少走弯路.有些程序员在学习的时候总是急功近利,这里看看 那里学学,最后都不能把该掌握的 ...
- Flask安装教程
第1步:确保本机已经安装有python,下载easy_install到本地某一目录,双击ez_setup.py,python将自动下载到python安装目录/Scripts 下面,然后在系统环境变量的 ...
- 在 ASP.NET CORE 中使用 SESSION (转载)
Session 是保存用户和 Web 应用的会话状态的一种方法,ASP.NET Core 提供了一个用于管理会话状态的中间件.在本文中我将会简单介绍一下 ASP.NET Core 中的 Session ...