【CF908G】New Year and Original Order
【CF908G】New Year and Original Order
题面
题解
设\(f[i][j][k][l]\)表示当前在第\(i\)位有\(j\)位大于等于\(k\),当前有没有卡上界的方案数
则枚举新加的数\(p\),有
\]
我们最后统计答案的时候枚举\(k\)
有
\]
为什么要乘那么多\(1\)呢?(下面是张图片)
代码(压行有点丑)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define rep(i, from, to) for(int i = (from); i <= (to); i++)
const int Mod = 1e9 + 7;
const int MAX_N = 1005;
void pls(int &x, int y) { x += y; if (x >= Mod) x -= Mod; }
char ch[MAX_N]; int a[MAX_N], N;
int ans, f[MAX_N][MAX_N][10][2];
int main () {
scanf("%s", ch + 1); N = strlen(ch + 1);
rep(i, 1, N) a[i] = ch[i] - '0';
rep(i, 0, 9) f[0][0][i][0] = 1;
rep(i, 0, N - 1) rep(j, 0, i) rep(k, 1, 9) rep(l, 0, 1) rep(p, 0, (l ? 9 : a[i + 1]))
pls(f[i + 1][j + (p >= k)][k][l | (p < a[i + 1])], f[i][j][k][l]);
rep(k, 1, 9) {
int res = 1;
rep(i, 1, N) pls(ans, 1ll * res * (f[N][i][k][0] + f[N][i][k][1]) % Mod), res = (10ll * res + 1) % Mod;
}
printf("%d\n", ans);
return 0;
}
【CF908G】New Year and Original Order的更多相关文章
- 【CF908G】New Year and Original Order(动态规划)
[CF908G]New Year and Original Order(动态规划) 题面 洛谷 CF 题解 设\(f[i][j][k][0/1]\)表示当前填到了第\(i\)位,有\(j\)个大于等于 ...
- 【CF908G】New Year and Original Order 数位DP
[CF908G]New Year and Original Order 题意:令S(i)表示将i中所有数位上的数拿出来,从小到大排序后组成一个新的数的值.如S(50394)=3459.求$\sum\l ...
- 【leetcode】Binary Tree Zigzag Level Order Traversal
Binary Tree Zigzag Level Order Traversal Given a binary tree, return the zigzag level order traversa ...
- 【leetcode】Binary Tree Zigzag Level Order Traversal (middle)
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...
- 【LeetCode】107 - Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- 【LeetCode】102 - Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- 【leetcode】429. N-ary Tree Level Order Traversal
problem 429. N-ary Tree Level Order Traversal solution1:Iteration /* // Definition for a Node. class ...
- 【树】Binary Tree Zigzag Level Order Traversal
题目: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from lef ...
- 【SQL】183. Customers Who Never Order
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
随机推荐
- hdu-3397 Sequence operation 线段树多种标记
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3397 题目大意: 0 a b表示a-b区间置为0 1 a b表示a-b区间置为1 2 a b表示a- ...
- 消息中间件--"rocketmq"02之QuickStart
依赖 <dependency> <groupId>com.alibaba.rocketmq</groupId> <artifactId>rocketmq ...
- Python3安装scrapy框架步骤
Python3安装scrapy框架步骤 1. 安装wheel a) Pip install wheel 2. 安装lxml Pip install lxml 3. ...
- Eclipse导入web项目发布项目时报Tomcat version 7.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 and 6 Web错误解决方案
Eclipse导入web项目后,将web项目加载到server进行发布时,提示Tomcat version 7.0 only supports J2EE 1.2, 1.3, 1.4, and Java ...
- SpringBoot实战(一)之构建RestFul风格
RestFul风格是一种非常流行的架构风格,相关实战可以参考我的这篇博客:SSM框架之RestFul示例 论文可参考:https://www.ics.uci.edu/~fielding/pubs/di ...
- uboot 移植 要点
1.第一 首先要 学会 shell 语法 比如 变量的 概念 变量的使用 ,if 语法 ,以及简单 IF 语法(与 或预算),以及 while for 循环 等等语法,才能看得懂 uboot ...
- 分布式消息通信ActiveMQ
消息中间件 消息中间件是指利用高效可靠的消息传递机制进行平台无关的数据交流,并且基于数据通信来进行分布式系统的集成.通过提供消息传递和消息排队模型,可以在分布式架构下扩展进程之间的通信. 消息中间件能 ...
- kvo本质探寻
一.概述 1.本文章内容,须参照本人的另一篇博客文章“class和object_getClass方法区别”加以理解: 2.基本使用: //给实例对象instance添加观察者,监听该实例对象的某个属性 ...
- 关于iOS Block当中为什么要用weakSelf和strongSelf的思考
场景:当你在某个界面请求网络数据的时候,用户不愿意等待点击了返回按钮,此时在Block当中用如下的方式使用weakSelf的话,有可能会奔溃(因为在并发编程的情况下,虽然在if判断的时候weaksel ...
- (1)linux和oracle---环境搭建
对linux和oracle一直是敬而远之,稍微有些了解.无奈由于工作需要这次要硬着头皮上了!@#!@@#$%^^ 对于重windows用户的我来说,简直是万种折磨. 算是做个记录吧,一定要坚持下去. ...