Order-Preserving Codes

Time Limit: 5000ms
Memory Limit: 65536KB

This problem will be judged on ZJU. Original ID: 2561
64-bit integer IO format: %lld      Java class name: Main

Special Judge

Binary code is a mapping of characters of some alphabet to the set of finite length bit sequences. For example, standard ASCII code is a fixed length code, where each character is encoded using 8 bits.

Variable length codes are often used to compress texts taking into account the frequencies of occurence of different characters. Characters that occur more often get shorter codes, while characters occuring less often -- longer ones.

To ensure unique decoding of variable length codes so called prefix codes are usually used. In a prefix code no code sequence is a proper prefix of another sequence. Prefix code can be easily decoded scanning the encoded sequence from left to right, since no code is the prefix of another, one always knows where the code for the current character ends and the new character starts.

Among prefix codes, the optimal code is known, so called Huffman code. It provides the shortest possible length of the text among all prefix codes that separatly encode each character with an integer number of bits.

However, as many other codes, Huffman code does not preserve character order. That is, Huffman codes for lexicographically ordered characters are not necessarily lexicographicaly ordered.

In this problem you are asked to develop a prefix code that would be optimal for the given text among all order-preserving prefix codes. Code is called order-preserving if for any two characters the code sequence for the character that goes earlier in the alphabet is lexicographically smaller.

Since text itself is not essential for finding the code, only the number of occurences of each character is important, only this data is given.

Input:

The input consists of several test cases

For each test case, the first line contains n -- the number of characters in the alphabet (2 <= n <= 2000). The next line contains n integer numbers -- the number of occurences of the characters in the text for which the code must be developed (numbers are positive and do not exceed 109). Characters are described in the alphabetical order.

Output:

For each test case, Output n bit sequences, one on a line -- the optimal order-preserving prefix code for the described text.

Sample Input:

5
1 8 2 3 1

Sample Output:

00
01
10
110
111
 

Source

Author

Andrew Stankevich
 
解题:平行四边形优化动态规划
$当i\leq i'\leq j\leq j' 有 sum[i][j]+sum[i'][j']\leq sum[i'][j]+sum[i][j']$
故可以用平行四边形优化
$s[i][j-1] \leq s[i+1][j]$
 
 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = ;
LL dp[maxn][maxn],sum[maxn];
int s[maxn][maxn],n;
void dfs(int x,int L,int R) {
if(L >= R) {
putchar('\n');
return;
}
if(x <= s[L][R]) {
putchar('');
dfs(x,L,s[L][R]);
} else {
putchar('');
dfs(x,s[L][R] + ,R);
}
}
int main() {
while(~scanf("%d",&n)) {
for(int i = ; i <= n; ++i) {
scanf("%lld",sum + i);
s[i][i] = i;
sum[i] += sum[i-];
}
for(int i = ; i <= n; ++i) {
for(int j = ; j + i - <= n; ++j) {
int k = j + i - ;
dp[j][k] = INF;
for(int t = s[j][k-]; t <= s[j+][k]; ++t) {
LL tmp = dp[j][t] + dp[t+][k] + sum[k] - sum[j-];
if(dp[j][k] > tmp) {
dp[j][k] = tmp;
s[j][k] = t;
}
}
}
}
for(int i = ; i <= n; ++i) dfs(i,,n);
}
return ;
}

ZOJ 2561 Order-Preserving Codes的更多相关文章

  1. table2excel使用

    原table2excel代码 /* * 采用jquery模板插件——jQuery Boilerplate * * Made by QuJun * 2017/01/10 */ //table2excel ...

  2. Cassandra 数据模型设计,根据你的查询来制定设计——反范式设计本质:空间换时间

    转自:http://www.infoq.com/cn/articles/best-practice-of-cassandra-data-model-design 不要把Cassandra model想 ...

  3. Method and Apparatus for Providing Highly-Scalable Network Storage for Well-Gridded Objects

    An apparatus comprising a plurality of storage nodes comprising a plurality of corresponding storage ...

  4. 细说 PEP 468: Preserving Keyword Argument Order

    细说 PEP 468: Preserving Keyword Argument Order Python 3.6.0 版本对字典做了优化,新的字典速度更快,占用内存更少,非常神奇.从网上找了资料来看, ...

  5. M面经Prepare: Positive-Negative partitioning preserving order

    Given an array which has n integers,it has both positive and negative integers.Now you need sort thi ...

  6. UVA-146 ID Codes

    It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In order to exerc ...

  7. System Error Codes

    很明显,以下的文字来自微软MSDN 链接http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx M ...

  8. uva146 ID codes

    Description It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In or ...

  9. ZOJ 3494 BCD Code(AC自动机+数位DP)

    BCD Code Time Limit: 5 Seconds      Memory Limit: 65536 KB Binary-coded decimal (BCD) is an encoding ...

随机推荐

  1. Java socket1

    注意: 网络编程不是等于网站编程.  html css JavaScript那些是网站编程,是构建在网络编程的基础之上的,网络编程是它的底层.    比方说qq,联动的游戏,这些是网络编程. 一般的网 ...

  2. JDBC连接Oracle工具类

    import java.sql.*;import java.util.ResourceBundle; /** * jdbc工具类,负责: * 1. 加载/注册数据库驱动程序 * 2. 获取数据库连接 ...

  3. java之数据处理,小数点保留位数

    1.返回字符串类型,保留后两位: public static String getRate(Object d) { return String.format("%.2f", d); ...

  4. 日常记录-代码中Background后Padding 失效

    近日,在开发过程中 遇到了 Layout 代码中设置 Background 后,padding失效的问题,只是在Android 4.4.4 和 4.4.2 的手机上遇到了. 网上搜索了下,说是 4.4 ...

  5. Request.Form("id")与Request.QueryString("id")的区别

    获取以表单提交的post类型的值,也就是获取<form method="post">这种方式提交的值request包含各种方式的值,没有指名是什麽,所以Request. ...

  6. 慎将MBTI测试用于招聘或就业:4星|《人格魅力修炼指南》

    人格魅力修炼指南:成为理想中的自己,就靠它了!(<哈佛商业评论>增刊) <哈佛商业评论>的11篇领导者人格魅力相关的文章.比较专业. 一些重要的信息:慎将MBTI测试用于“招聘 ...

  7. A Convolution Tree with Deconvolution Branches: Exploiting Geometric Relationships for Single Shot Keypoint Detection

    作者:嫩芽33出处:http://www.cnblogs.com/nenya33/p/6817781.html 版权:本文版权归作者和博客园共有 转载:欢迎转载,但未经作者同意,必须保留此段声明:必须 ...

  8. CentOS7 Install Consul

    Centos7 Install Consul 原文链接:http://www.cnblogs.com/caoguo/p/5959962.html 1) 环境 2) 安装 # yum install - ...

  9. redis-3.0.1 sentinel 主从高可用 详细配置

    最近项目上线部署,要求redis作高可用,由于redis cluster还不是特别成熟,就选择了redis sentinel做高可用.redis本身有replication,实现主从备份.结合sent ...

  10. ALTER TRIGGER - 修改一个触发器的定义

    SYNOPSIS ALTER TRIGGER name ON table RENAME TO newname DESCRIPTION 描述 ALTER TRIGGER 改变一个现有触发器的属性. RE ...