【CF908G】New Year and Original Order

题面

洛谷

题解

设\(f[i][j][k][l]\)表示当前在第\(i\)位有\(j\)位大于等于\(k\),当前有没有卡上界的方案数

则枚举新加的数\(p\),有

\[f[i+1][j+(p\geq k)][k][l|(p<a_i)]=\sum f[i][j][k][l]
\]

我们最后统计答案的时候枚举\(k\)

\[ans=\underbrace{111...11}_{j个1}*(f[i][j][k][0]+f[i][j][k][1])
\]

为什么要乘那么多\(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的更多相关文章

  1. 【CF908G】New Year and Original Order(动态规划)

    [CF908G]New Year and Original Order(动态规划) 题面 洛谷 CF 题解 设\(f[i][j][k][0/1]\)表示当前填到了第\(i\)位,有\(j\)个大于等于 ...

  2. 【CF908G】New Year and Original Order 数位DP

    [CF908G]New Year and Original Order 题意:令S(i)表示将i中所有数位上的数拿出来,从小到大排序后组成一个新的数的值.如S(50394)=3459.求$\sum\l ...

  3. 【leetcode】Binary Tree Zigzag Level Order Traversal

    Binary Tree Zigzag Level Order Traversal Given a binary tree, return the zigzag level order traversa ...

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

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

  6. 【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, ...

  7. 【leetcode】429. N-ary Tree Level Order Traversal

    problem 429. N-ary Tree Level Order Traversal solution1:Iteration /* // Definition for a Node. class ...

  8. 【树】Binary Tree Zigzag Level Order Traversal

    题目: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from lef ...

  9. 【SQL】183. Customers Who Never Order

    Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...

随机推荐

  1. CentOS7.X安装Redis-4.0.8以及Redis集群搭建

    安装redis 安装前的准备 yum install \ vim \ wget \ make \ gcc \ gcc-c++ \ automake \ autoconf \ -y \ 下载解压并安装 ...

  2. HDU 1079 Calendar Game (博弈论-sg)

    版权声明:欢迎关注我的博客,本文为博主[炒饭君]原创文章.未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/32336485 C ...

  3. Odoo启动配置文件

    转载请注明原文地址:https://www.cnblogs.com/cnodoo/p/9278687.html 1:--xmlrpc-port=<端口> 命令选项充许我们将服务器实例的侦听 ...

  4. consul搭建(初步)

    http://www.cnblogs.com/java-zhao/p/5375132.html https://blog.csdn.net/u010246789/article/details/517 ...

  5. 在Java中使用Maven配置的版本信息

    我们在使用maven开发一些项目的时候需要知道当前的版本状态,但版本状态储存在pom.xml文件中,可以采用以下2种方式进行获取: 1. 采用xml解析的方式去获取pom文件的{project.ver ...

  6. 【51nod 1685】 第K大区间2

    题目描述: 定义一个长度为奇数的区间的值为其所包含的的元素的中位数.现给出n个数,求将所有长度为奇数的区间的值排序后,第K大的值为多少. 样例解释: [l,r]表示区间的值 [1]:3 [2]:1 [ ...

  7. Linux BLE 基于 树莓派

    1.参考资料:Linux(RaspberryPi)上使用BLE低功耗蓝牙 使用bluez协议栈方法有用 2.Linux下Bluez的编程实现 3.和菜鸟一起学linux之bluez学习记录2 4.BL ...

  8. wordpress安装(ubuntu+nginx+php+mariadb)

    一.   环境 ubuntu12.04.4 nginx 1.6.0 mariadb 10.0 更新系统补丁 sudo apt-get update sudo apt-get dist-upgrade ...

  9. JAVA类加载和初始化

    JAVA类的加载和初始化 一.类的加载和初始化过程 JVM将类的加载分为3个步骤: 1.加载(Load):class文件创建Class对象. 2.链接(Link) 3.初始化(Initialize) ...

  10. 微服务之配置中心ConfigKeeper

    在微服务架构中,配置中心是必不可少的基础服务.ConfigKeeper已开源,本文将深度分析配置中心的核心内容,错过「Spring Cloud中国社区北京沙龙-2018.10.28 」的同学将从本篇文 ...