908G New Year and Original Order】的更多相关文章

传送门 分析 代码 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cctype> #include<cmath> #include<cstdlib> #include<ctime> #include<queue> #include<…
[CF908G]New Year and Original Order(动态规划) 题面 洛谷 CF 题解 设\(f[i][j][k][0/1]\)表示当前填到了第\(i\)位,有\(j\)个大于等于\(k\)的数,是否卡到上界的方案数. 这个东西算完之后,等价于默认排好序了. 看起来可以枚举每个数字出现在第几位了. 然而实际上不知道这个数字的出现次数,所以不能按照\(10^j*k\)这样子计算贡献. 怎么办呢,假设前面有\(j\)个数大于\(k\)的数,那么就产生\(\sum_{i=0}^{j…
[CF908G]New Year and Original Order 题意:令S(i)表示将i中所有数位上的数拿出来,从小到大排序后组成一个新的数的值.如S(50394)=3459.求$\sum\limits_{i=1}^nS(i)$. $n\le 10^{700}$. 题解:比较难的数位DP.我们考虑分别计算每个数字的贡献.令f0[i][a][b]表示考虑到第i位数,其中数字a的最高为是b的数的数量,再令f1[i][a][b]表示a这个数的贡献.再设g0,g1表示小于等于n的所有数的DP值.…
G. New Year and Original Order time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Let S(n) denote the number that represents the digits of n in sorted order. For example, S(1) = 1, S(5) = 5, …
[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]+…
\(\mathcal{Description}\)   Link.   对于 \(x\in\mathbb N^*\),令 \(s(x)\) 表示将 \(x\) 十进制下的各位数码排序后得到的十进制数的值.求 \(\sum_{i=1}^X s(i)\) 对 \((10^9+7)\) 取模的结果.   \(X\le10^{700}\). \(\mathcal{Solution}\)   下记 \(m=10\)(进制),\(n=\lceil\log_mX\rceil\). \(\mathcal{Cas…
题目大意: 定义\(R(x) = 每个数在各数位排序后得到的数\) 例如:\(R(321597) = 123579\) 给定一个\(n<=10^{700}\),求\(\sum _{i=1}^n R(i)\).答案模上\(10^9+7\). 思路与解法: 难度比较大的一题.显然是要数位\(DP\)的. 最直白的想法就是:求出\(g[i][j]\)表示数字在\(R(x)\)的第\(j\)位出现的次数. 有了这个我们就可以计算答案了. 但是这个玩意不好\(DP\)处理. 考虑数字\(num\)在\(f…
传送门 看到数据范围到\(10^{700}\)毫无疑问数位DP.那么我们最重要的问题是如何有效地维护所有数位排序之后的数的值. 对于某一个数\(x\),设\(f_{x,i} (i \in [1,9])\)表示\(x\)中的所有数位的值\(\geq i\)的数位数量,比如说\(f_{6345982 , 7} = 2 , f_{1982777 , 7} = 5\).那么\(x = \sum\limits_{i=1}^9 \sum\limits_{j=0}^{f_{x,i} - 1} 10^i = \…
题面 题意翻译 给定$n<=10^{700}$,问$1$到$n$中每个数在各数位排序后得到的数的和.答案$mod\;10^9+7$. 题解 考虑设$f[i][j][k][0/1]$表示前$i$位有$j$位的数字大小$\geq k$,是否严格小于$n$的方案数 转移时,枚举第$i+1$位填$p$ $$ f[i+1][j+(p\geq k)][k][l|(p < a_{i+1})]=\sum f[i][j][k][l] $$ 答案就是 $$ \sum_k\sum_j (f[n][j][k][0]+…
给n<=10^700,问1到n中每个数在各数位排序后得到的数的和.答案膜1e9+7. 一看就是数位DP啦..然而并没有什么思路.. 可以尝试统计n(i,j)表示数j在第i位的出现次数,知道了这个数组后就可以算答案了.可以枚举j,做一次DP,f(a,b,0/1)--考虑第a~n个数,有b个j,是否大于给定数字(因为当前大于给定数字不一定dp到前面的数就大于,所以当前大于给定数字的数也是有贡献的),等等光知道有多少j并不能确定第i位是否有j,行不通. 套路--k(i,j)表示第i位出现的>=j的数…
又一次降智…… (数位 DP 原来可以写这么短,学到了) 问题可以转化为求数位中 $\ge k$ 的有恰好 $j$ 位的数的个数.设为 $c_{j,k}$. 那么答案就是:(考虑把 $k$ 的贡献拆开,比如 $9$ 的贡献拆成 $1$ 的贡献的 $9$ 倍,然后分配到 $1$ 到 $9$) $$\sum_{1\le j\le n,1\le k\le 9}c_{j,k}\underbrace{111\dots111}_{j}$$ 求 $c_{j,k}$ 可以数位 DP.(此处不是记忆化搜索的形式,…
A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fewer than two…
463. Island Perimeterhttps://leetcode.com/problems/island-perimeter/就是逐一遍历所有的cell,用分离的cell总的的边数减去重叠的边的数目即可.在查找重叠的边的数目的时候有一点小技巧,就是沿着其中两个方向就好,这种题目都有类似的规律,就是可以沿着上三角或者下三角形的方向来做.一刷一次ac,但是还没开始注意codestyle的问题,需要再刷一遍. class Solution { public: int islandPerime…
用 Sublime 已经有很长一段时间,很舒适,很贴心,根本停不下来.之前因为是开发页游,所以是用 AS3 开发,近段时间,新开了个手游项目,引擎方面选定了 Unity3D,老实说,之前没有太多的 3D 的概念,只是自己偶尔会下个 AS3 写的 3D 引擎玩一下,折腾折腾,并没有实际的工作中用到过相关的东西,如今项目需要用 Unity3D,有些兴奋,这可不是自己折腾的小打小闹了. Unity 支持的脚本有3种:C#, JS, Boo,我们这边是打算使用 C#,在使用语言的问题上并没有做太多的讨论…
B1027. 打印沙漏 (20) Description: 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个"*",要求按下列格式打印 ***** *** * *** ***** 所谓"沙漏形状",是指每行输出奇数个符号:各行符号中心对齐:相邻两行符号数差2:符号数先从大到小顺序递减到1,再从小到大顺序递增:首尾符号数相等. 给定任意N个符号,不一定能正好组成一个沙漏.要求打印出的沙漏能用掉尽可能多的符号. Input: 输入在一行给出1个正整数N(&…
第三章 算法 前言:许多人对算法的看法是截然不同的,我之前提到过了.不过,我要说的还是那句话:算法体现编程思想,编程思想指引算法. 同时,有许多人认为简单算法都太简单了,应当去学习一些更为实用的复杂算法.不过,许多复杂算法都是从简单算法演绎而来的,这里就不一一举例了.而且,算法千千万万.更为重要的是从算法中体会编程的思想. 4.1 简单问题算法 PS:接下来是一些入门问题,简单到都没有具体算法可言.但这些问题是我们当初对算法的入门.如果不喜欢,可以跳过. 实例111 任意次方后的最后三位 问题:…
题目链接: Queue Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1093    Accepted Submission(s): 566 Problem Description N people numbered from 1 to N are waiting in a bank for service. They all stan…
本题要求在O(n)时间内求解.用delta储存相邻两个数的差,如果相邻的两个delta不同负号,那么说明子序列摇摆了一次.参看下图的nums的plot.这个例子的答案是7.平的线段部分我们支取最左边的一个点.除了最左边的边界点,我们要求delta != 0, 并且newDelta * delta <= 0.(这里不能只取<号),否则dot 5和7就会被忽略,因为他们的newDelta*delta = 0. def wiggleMaxLength(self, nums): ""…
UVa 101 The Blocks Problem 一道纯模拟题 The Problem The problem is to parse a series of commands that instruct a robot arm in how to manipulate blocks that lie on a flat table. Initially there are nblocks on the table (numbered from 0 to n-1) with block bi…
Given an array with positive and negative integers. Re-range it to interleaving with positive and negative integers. Note: You are not necessary to keep the original order of positive integers or negative integers. Example Given [-1, -2, -3, 4, 5, 6]…
题目描述 Most of you have played card games (and if you haven’t, why not???) in which the deck of cards is randomized by shuffling it one or more times.A perfect shuffle is a type of shuffle where the initial deck is divided exactly in half, and the two hal…
In this installment, I’ll be talking about the (early) Z pipeline and how it interacts with rasterization. Like the last part, the text won’t proceed in actual pipeline order; again, I’ll describe the underlying algorithms first, and then fill in the…
题目描述: Given any ) characters, you are asked to form the characters into the shape of U. For example, "helloworld" can be printed as: h d e l l r lowo That <= n2 <= N } with n1 + n2 + n3 - = N. 输入: There are multiple test cases.Each and no…
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=37   The Blocks Problem  Background Many areas of Computer Science use simple, abstract domains for both analytical and empiric…
Given an array with positive and negative integers. Re-range it to interleaving with positive and negative integers. Example Given [-1, -2, -3, 4, 5, 6], after re-range, it will be[-1, 5, -2, 4, -3, 6] or any other reasonable answer. Note You are not…
控制台程序. Arrays类中的sort()静态方法把传送为参数的数组元素按升序方式排序. 对于第一个参数类型是Object[]的sort()方法来说,可以传送任意类型的数组.如果使用sort()方法的任何一个版本对对象数组排序,对象就必须支持Comparable<>接口,因为sort()方法使用了compareTo()方法. sort()方法的另外两个用来对对象数组排序的版本是参数化方法.它们在对数组排序是,使用外部的比较器对象来确定对象的顺序.比较器对象的类必须实现java.util.Co…
Given a string which contains only letters. Sort it by lower case first and upper case second. Note It's not necessary to keep the original order of lower-case letters and upper case letters. Example For "abAcD", a reasonable answer is "acb…
http://poj.org/problem?id=2192 Zipper Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17585   Accepted: 6253 Description Given three strings, you are to determine whether the third string can be formed by combining the characters in the…
代码参考:http://www.hankcs.com/program/uva-q101-the-blocks-problem.html Description Background Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of planning and robotics…
Description Given three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in its original order. For example,…