【2005-2006 ACM-ICPC, NEERC, Moscow Subregional Contest】Problem J. Jack-pot
简单dfs,差分一下A数组和建出字典树能写得更方便,若不这么做代码时就会像我一样难受。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 100003;
int a[13][N], n, m, k, A[13], pos[13][N];
ll dfs(int tmp, int l, int r, int f) {
if (tmp > m) {
return 1ll * (r - l + 1) * A[m];
}
int und = l;
ll ans = 1000000000000000ll;
if (r - l + 1 < k || (a[tmp][l] != 0) || (a[tmp][r] != k - 1)) {
ans = 1ll * A[tmp - 1] * (r - l + 1);
if (a[tmp][l] != 0) pos[tmp - 1][f] = 0;
if (a[tmp][r] != k - 1) pos[tmp - 1][f] = -(k - 1);
}
for (int i = l + 1; i <= r; ++i)
if (a[tmp][i] != a[tmp][i - 1] && a[tmp][i] != a[tmp][i - 1] + 1) {
ans = 1ll * A[tmp - 1] * (r - l + 1);
pos[tmp - 1][f] = -(a[tmp][i - 1] + 1);
break;
}
for (int i = l + 1; i <= r + 1; ++i)
if (i > r || a[tmp][i] != a[tmp][und]) {
int num = dfs(tmp + 1, und, i - 1, und) + 1ll * A[tmp - 1] * (r - l + 1 - (i - und));
if (num < ans) {
ans = num;
pos[tmp - 1][f] = und;
}
und = i;
}
return ans;
}
char s[13];
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= m; ++i) scanf("%d", &A[i]);
for (int i = 1; i <= n; ++i) {
scanf("%s", s + 1);
for (int j = 1; j <= m; ++j)
a[j][i] = s[j] - '0';
}
ll ans = dfs(1, 1, n, 1); int tmp = 1;
for (int i = 1; i <= m; ++i) {
tmp = pos[i - 1][tmp];
if (tmp <= 0) {
printf("%d", -tmp);
for (int j = i + 1; j <= m; ++j) putchar('0');
break;
}
printf("%d", a[i][tmp]);
}
printf("\n%lld\n", ans);
return 0;
}
【2005-2006 ACM-ICPC, NEERC, Moscow Subregional Contest】Problem J. Jack-pot的更多相关文章
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 G. Garden Gathering
Problem G. Garden Gathering Input file: standard input Output file: standard output Time limit: 3 se ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time
Problem D. Delay Time Input file: standard input Output file: standard output Time limit: 1 second M ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest
2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...
- 2016 NEERC, Moscow Subregional Contest K. Knights of the Old Republic(Kruskal思想)
2016 NEERC, Moscow Subregional Contest K. Knights of the Old Republic 题意:有一张图,第i个点被占领需要ai个兵,而每个兵传送至该 ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution
从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...
- 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing
[链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 K. King’s Rout
K. King's Rout time limit per test 4 seconds memory limit per test 512 megabytes input standard inpu ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 I. Illegal or Not?
I. Illegal or Not? time limit per test 1 second memory limit per test 512 megabytes input standard i ...
随机推荐
- 使用TS+Sequelize实现更简洁的CRUD
如果是经常使用Node来做服务端开发的童鞋,肯定不可避免的会操作数据库,做一些增删改查(CRUD,Create Read Update Delete)的操作,如果是一些简单的操作,类似定时脚本什么的, ...
- linux学习记录.5.git & github
参考 https://www.linuxidc.com/Linux/2016-11/136769.htm 安装 安装 Git: apt-get install git 查看当前版本: git --ve ...
- c++细节--section1
1.register声明的变量为寄存器变量,因此没有地址,不能对它取地址操作. 2.[用错sizeof]当数组作为函数参数传递时,数组会退化为同类型的指针. 3.每个成员在成员初始化列表中只能出现一次 ...
- console.dir() 与 console.dirxml() 的使用
在调试JavaScript程序时,有时需要dump某些对象的详细信息.通过手工编写JavaScript代码可以完成这一工作:针对对象的属性进行循环,将循环到的每一个属性值打印出来:可见,这一过程是比较 ...
- 可能是最漂亮的Spring事务管理详解
Java面试通关手册(Java学习指南):https://github.com/Snailclimb/Java_Guide 微信阅读地址链接:可能是最漂亮的Spring事务管理详解 事务概念回顾 什么 ...
- shutdown系统调用
/* * Shutdown a socket. */ SYSCALL_DEFINE2(shutdown, int, fd, int, how) { int err, fput_needed; stru ...
- mysql只读模式的设置方法与实验【转】
在MySQL数据库中,在进行数据迁移和从库只读状态设置时,都会涉及到只读状态和Master-slave的设置和关系. 经过实际测试,对于MySQL单实例数据库和master库,如果需要设置为只读状态, ...
- MVVM模式的命令绑定
命令绑定要达到的效果 命令绑定要关注的核心就是两个方面的问题,命令能否执行和命令怎么执行.也就是说当View中的一个Button绑定了ViewModel中一个命令后,什么时候这个Button是可用的, ...
- HDU 6061 RXD and functions
题目链接:HDU-6061 题意:给定f(x),求f(x-A)各项系数. 思路:推导公式有如下结论: 然后用NTT解决即可. 代码: #include <set> #include < ...
- Git如何设置多个用户
前言 由于我们在使用GitHub时,通常不希望带有公司信息,所以需要独立的Git账户来提交练习代码,本文记录一下如何配置多个Git账户并创建公钥 正文 1.首先进入~/.ssh文件夹 2.然后创建一个 ...