Codeforces Round #300 Quasi Binary(DP)
2 seconds
256 megabytes
standard input
standard output
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
The first line contains a single integer n (1 ≤ n ≤ 106).
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
- 9
- 9
1 1 1 1 1 1 1 1 1
- 32
- 3
10 11 11
【题意】给出一种定义数,这种数每一位不是0就是1,给你一个n,问你最少可以由多少定义数组成,分别列出这些定义数。
【分析】简单DP,先预处理出所有可能的数,然后背包。
- #include <bits/stdc++.h>
- #define pb push_back
- #define mp make_pair
- #define vi vector<int>
- #define inf 0x3f3f3f3f
- #define met(a,b) memset(a,b,sizeof a)
- using namespace std;
- typedef long long LL;
- const int N = 1e6+;
- int n;
- int dp[N],vis[N],pre[N];
- vector<int>vec,ans;
- void init(){
- queue<int>q;
- q.push();
- vis[]=;
- while(!q.empty()){
- int u=q.front();
- q.pop();
- vec.pb(u);
- int k = u*+;
- if(k<=&&!vis[k]){
- q.push(k);
- vis[k]=;
- }
- k = u*+;
- if(k<=&&!vis[k]){
- q.push(k);
- vis[k]=;
- }
- }
- }
- int main(){
- scanf("%d",&n);
- if(!n){
- printf("1\n0\n");
- return ;
- }
- init();
- met(dp,inf);
- dp[]=;
- for(int i=;i<=n;i++){
- for(int x : vec){
- if(i-x>=&&dp[i-x]+<dp[i]){
- dp[i]=dp[i-x]+;
- pre[i]=i-x;
- }
- }
- }
- int k=n;
- while(k){
- int s=k-pre[k];
- k=pre[k];
- ans.pb(s);
- }
- printf("%d\n",dp[n]);
- for(auto x:ans){
- printf("%d ",x);
- }printf("\n");
- return ;
- }
Codeforces Round #300 Quasi Binary(DP)的更多相关文章
- Educational Codeforces Round 51 D. Bicolorings(dp)
https://codeforces.com/contest/1051/problem/D 题意 一个2*n的矩阵,你可以用黑白格子去填充他,求联通块数目等于k的方案数,答案%998244353. 思 ...
- Codeforces Round #219 (Div. 1)(完全)
戳我看题目 A:给你n个数,要求尽可能多的找出匹配,如果两个数匹配,则ai*2 <= aj 排序,从中间切断,分成相等的两半后,对于较大的那一半,从大到小遍历,对于每个数在左边那组找到最大的满足 ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
- CodeForces - 710E Generate a String (dp)
题意:构造一个由a组成的串,如果插入或删除一个a,花费时间x,如果使当前串长度加倍,花费时间y,问要构造一个长度为n的串,最少花费多长时间. 分析:dp[i]---构造长度为i的串需要花费的最短时间. ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
- Codeforces 536D - Tavas in Kansas(dp)
Codeforces 题目传送门 & 洛谷题目传送门 其实这题本该 2019 年 12 月就 AC 的(详情请见 ycx 发此题题解的时间),然鹅鸽到了现在-- 首先以 \(s,t\) 分别为 ...
- Codeforces Round #249 (Div. 2) (模拟)
C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces 295D - Greg and Caves(dp)
题意: 给出一个 \(n \times m\) 的矩阵,需对其进行黑白染色,使得以下条件成立: 存在区间 \([l,r]\)(\(1\leq l\leq r\leq n\)),使得第 \(l,l+1, ...
- Codeforces 467C George and Job(DP)
题目 Source http://codeforces.com/contest/467/problem/C Description The new ITone 6 has been released ...
随机推荐
- 知问前端——cookie插件
Cookie是网站用来在客户端保存识别用户的一种小文件.一般可以保存用户登录信息.购物数据信息等一系列微小信息. 一.使用cookie插件 官方网站:http://plugins.jquery.com ...
- CentOS 7 vim显示中文乱码
使用xshell的时候,发现有时候中文显示有乱码,一开始以为是Xshell没设置好,后来检查了一下xshell<<文件<<属性<<终端:右侧编码,显示的是Unico ...
- CentOS7 搭建Apache环境
一.安装 yum -y install httpd 二.配置 主路径:/etc/httpd/ Apache目录说明 1 2 3 4 5 6 drwxr-xr-x 2 root root 4096 Ma ...
- SQL语句语法简介
SQL命令一般分为DQL.DML.DDL几类: DQL:数据查询语句,基本就是SELECT查询命令,用于数据查询 DML:Data Manipulation Language的简称,即数据操纵语言,主 ...
- Linux进程调度与源码分析(一)——简介
本系列文章主要是近期针对Linux进程调度源码进行阅读与分析后的经验总结,分析过程中可能结合部分Linux网络编程的相关知识以便于理解,加深对Linux进程调度的理解和知识分享. 本系列文章主要结合L ...
- python实战===用python识别图片中的中文
需要安装的模块 PIL pytesseract 需要下载的工具: http://download.csdn.net/download/bo_mask/10196285 因为之前百度云的链接总失效,所以 ...
- pam_examples
blank.c /* * $Id$ */ /* Andrew Morgan (morgan@parc.power.net) -- a self contained `blank' * applicat ...
- 读取BMP图像size的时候与操作和左移的原因
在读取一个bmp图像的时候,我们会将它的大小读取出来,如果还不清楚bmp的文件结构,那就先看一下这篇博客. 看完我将假设你已经明白所表示的意义.那么,对于bfSize, 它的表示数字为 50 00 0 ...
- 【LOJ6201】【bzoj4939】【YNOI2016】掉进兔子洞
一道比较简单的莫队…… 用bitset维护三个区间的交元素. #include<bits/stdc++.h> ; ; #define UI unsigned int #define rep ...
- js对页面对float类型的数据格式化处理
<script> document.write(parseFloat(<s:property value="assureterm"/>)); ...