Sicily 2372. Non-Decreasing Digits
来源:互联网 发布:qt淘宝互刷平台 编辑:程序博客网 时间:2024/04/29 08:09
用一个数组arr[i][j]储存,i表示有几位数,j表示尾数不大于j的有几个
随便写一下就能发现规律:
两位数时最后一位大于j的个数分别为:1,3,6 ,10,15,21,28,36 ,45 ,55;
两位数时最后一位大于j的个数分别为:1,4,10,20,35,56,84,120,165,220
i>=2时:arr[i][j]=arr[i-1][j]+arr[i][j-1]
注意i为1的情况就好,直接输出10
int 会爆表,用 long long
#include <iostream>using namespace std;long long arr[65][10];void deal(){for(int i=1; i <= 64; ++i)arr[i][0]=1;for(int i=1; i < 10; ++i)arr[1][i]=arr[1][i-1]+1;for(int i=2; i <= 64; ++i){for(int j=1; j < 10; ++j)arr[i][j]=arr[i-1][j]+arr[i][j-1];} }int main(){deal();int test;cin >> test;while(test--){int num,n;cin >> num >> n;cout << num << " " << arr[n][9] << endl;}}
0 0
- Sicily 2372. Non-Decreasing Digits
- 32:C·Non-Decreasing Digits
- 【数论】Non-Decreasing Digit
- 665. Non-decreasing Array
- 665. Non-decreasing Array
- 665. Non-decreasing Array
- 665. Non-decreasing Array
- Non-decreasing Array
- LeetCode Non-decreasing Array
- Non-decreasing Array
- leetcode-Non-decreasing Array
- leetCode-Non-decreasing Array
- 665. Non-decreasing Array
- 665. Non-decreasing Array
- 665. Non-decreasing Array
- 665. Non-decreasing Array
- LeetCode-665 Non-decreasing Array
- LeetCode 665. Non-decreasing Array
- 将博客搬至51CTO
- 【机房重构】— 登陆折射出外观模式
- 18.4Sum
- CentOS7装机后要做的一些事
- get与post区别
- Sicily 2372. Non-Decreasing Digits
- asp.net页面间传值方式
- PAT(BASIC)1039. 到底买不买(20)
- 【扫描线】 HDU 1542 Atlantis 面积并
- 聚类算法
- 关于反射创建对象的演示
- 常用类
- Python核心编程例子userpw
- 详谈单链表之合并and冒泡排序