题目相关

题目链接

AtCoder Beginner Contest 167 C题,https://atcoder.jp/contests/abc167/tasks/abc167_c。

Problem Statement

Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his understanding level of each of the M algorithms is 0.

Takahashi is visiting a bookstore, where he finds NN books on algorithms. The i-th book (1 ≤ i ≤ N) is sold for Ci yen (the currency of Japan). If he buys and reads it, his understanding level of the jj-th algorithm will increase by Ai,j for each j (1 ≤ j ≤ M). There is no other way to increase the understanding levels of the algorithms.

Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Input

Input is given from Standard Input in the following format:

N M X
C1 A1,1 A1,2 ... A1,M
C2 A2,1 A2,2 ... A2,M
.
.
.
CN AN,1 AN,2 ... AN,M

Output

If the objective is not achievable, print -1; otherwise, print the minimum amount of money needed to achieve it.

Samples1

Sample Input 1

3 3 10
60 2 2 4
70 8 7 9
50 2 3 9

Sample Output 1

120

Explaination

Buying the second and third books makes his understanding levels of all the algorithms 10 or higher, at the minimum cost possible.

Sample Input 2

3 3 10
100 3 1 4
100 1 5 9
100 2 6 5

Sample Output 2

-1

Explaination

Buying all the books is still not enough to make his understanding levels of all the algorithms 10 or higher.

Sample Input 3

8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2

Sample Output 3

1067

Constraints

  • All values in input are integers.
  • 1 ≤ N, M ≤ 12
  • 1 ≤ X ≤ 10^5
  • 1 ≤ Ci ≤10^5
  • 0 ≤ Ai,j ≤ 10^5

题解报告

本题含义

告诉我们 N 本书,M 个算法,第 i 本书的售价是 Ci,读第 i 本书对第 j 个算法理解能力将提升 Ai,j。要求我们找到最小的代价,满足我们对 M 个算法的理解都能到达 X。如果没有,输出 -1。

讲真,看到这个题目,当时就炸裂了。我去,AtCoder Beginner Contest 的惯例,前面 4 题基本都不涉及到复杂算法。看到本题,我的第一反应是背包问题。后面仔细分析完样例数据后,可以使用 DFS 来解决。

样例数据分析

从数学角度上看,本题就是满足条件的搜索过程。

样例数据1

根据样例数据 1,我们知道一共有 3 本书,3 种算法,要求达到 10 点了解度。下面我们将数据进行一下简单的加工,以方便我们分析。

(1) 60 2 2 4
(2) 70 8 7 9
(3) 50 2 3 9

每组数据前面括号表示编号。这样我们知道就是在全部的组合中找到最小的代价。因此我们的能的组合数为:

(1)
(2)
(3)
(1) (2)
(1) (3)
(2) (3)
(1) (2) (3)

上面什么意思呢?

1、读一本书,看是否满足对 M 种算法达到了解度 X。这样我们的组合可能性有 C(n, 1) 种,因此是 C(3, 1)=3,对应的可能性是(1)、(2)或者(3)。如果有满足条件,记录下最小的代价。

2、读两本书,看是否满足对 M 种算法达到了解度 X。这样我们的组合可能性有 C(n, 2) 种,因此是 C(3, 2)=3,对应的可能性是(1) (2)、(1) (3)或者(2) (3)。如果有满足条件,记录下最小的代价。

3、读两三书,看是否满足对 M 种算法达到了解度 X。这样我们的组合可能性有 C(n, 3) 种,因此是 C(3, 3)=1,对应的可能性是(1) (2) (3)。如果有满足条件,记录下最小的代价。

这样所有的组合搜索完成后,我们就可以得到答案。具体过程请参看下表。

方案 算法了解度 代价 结论
(1) 2 2 4 60 不满足要求
(2) 8 7 9 70 不满足要求
(3) 2 3 9 50 不满足要求
(1) (2) 10 9 13 130 不满足要求
(1) (3) 4 5 13 110 不满足要求
(2) (3) 10 10 18 120 满足要求
(1) (2) (3) 12 12 22 180 满足要求

根据上表,我们可以看出,满足所有算法都达到 10 了解度的解决方案有 2 种,即 (2) (3) 和 (1) (2) (3),其中最小代价为 120。

样例数据2

样例数据 2 一共有 3 本书,3 种算法,要求达到 10 点了解度。

具体过程请参看下表。

方案 算法了解度 代价 结论
(1) 3 1 4 100 不满足要求
(2) 1 5 9 100 不满足要求
(3) 2 6 5 100 不满足要求
(1) (2) 4 6 13 200 不满足要求
(1) (3) 5 7 9 200 不满足要求
(2) (3) 3 11 14 200 不满足要求
(1) (2) (3) 6 12 18 300 不满足要求

根据上表,我们可以看出,没有满足所有算法都达到 10 了解度的解决方案,因此输出 -1。

样例数据3

样例数据 3 一共有 8 本书,5 种算法,要求达到 22 点了解度。因此一共有 C(8,1)+C(8,2)+C(8,3)+C(8,4)+C(8,5)+C(8,6)+C(8,7)+C(8,8)=8+28+56+70+56+26+8=254 种。

由于数据量比较大,我就不写了。

数据范围分析

N 的最大值为 12,因此计算量是有限的。C(12,1)+C(12,2)+C(12,3)+C(12,4)+C(12,5)+C(12,6)+C(12,7)+C(12,8)+C(12,9)+C(12,10)+C(12,11)+C(12,12)=12+66+220+495+792+924+792+495+220+66+12=4094 种。

X 的最大值为 10^5。int 表示可以解决。

Ci 的最大值为 10^5。因此 12 本书的价格最大值为 12*10^5=1.2*10^6,int 表示可以解决。

Ai,j 的最大值为 10^5。因此 12 本书的了解度最大值为 12*10^5=1.2*10^6,int 表示可以解决。

算法设计

通过分析,我们知道可以使用 DFS 来解决问题,因此本题套用 DFS 模板即可。DFS 的解题套路可以参考这个文章,https://blog.csdn.net/justidle/article/details/104925699。因此本题的算法就两步:

1、读入数据。

2、开始 DFS。

DFS 搜索顺序

我们参考样例输入 1 的数据,DFS 的搜索过程如下:

(1) -> (1) (2) -> (1) (2) (3) -> (2) -> (2) (3) -> (1) (3) -> (3)

AC 参考代码

AtCoder题解——Beginner Contest 167——C - Skill Up相关推荐

  1. AtCoder题解——Beginner Contest 170——F - Pond Skater

    题目相关 题目链接 AtCoder Beginner Contest 170 F题,https://atcoder.jp/contests/abc170/tasks/abc170_f. Problem ...

  2. AtCoder题解——Beginner Contest 170——E - Smart Infants

    题目相关 题目链接 AtCoder Beginner Contest 170 E 题,https://atcoder.jp/contests/abc170/tasks/abc170_e. Proble ...

  3. AtCoder题解——Beginner Contest 179——D - Leaping Tak

    题目相关 题目链接 AtCoder Beginner Contest 179 D 题,https://atcoder.jp/contests/abc179/tasks/abc179_d. Proble ...

  4. AtCoder Beginner Contest 167 D Teleporter 找周期

    AtCoder Beginner Contest 167   比赛人数11940  比赛开始后15分钟看到A题,之后每隔一分钟,看到一道题,在比赛开始后第21分钟看到所有题 AtCoder Begin ...

  5. AtCoder Beginner Contest 167 F.Bracket Sequencing

    AtCoder Beginner Contest 167 F.Bracket Sequencing 题目链接 判断括号匹配的字符串问题~ 首先给出的所有字符串的左右括号数是要匹配的,这个很好判断,用一 ...

  6. AtCoder Beginner Contest 167 A Registration 字符串比较

    AtCoder Beginner Contest 167   比赛人数11940  比赛开始后15分钟看到A题,之后每隔一分钟,看到一道题,在比赛开始后第21分钟看到所有题 AtCoder Begin ...

  7. AtCoder题解 —— AtCoder Beginner Contest 182 —— D - Wandering

    题目相关 题目链接 AtCoder Beginner Contest 182 D 题,https://atcoder.jp/contests/abc182/tasks/abc182_d. Proble ...

  8. AtCoder Beginner Contest 246 A~E 题解 Bishop 2

    AtCoder Beginner Contest 246 A~E 题解 A Four Points 题意 给你矩形的三个顶点,输出剩下那个 思路 把横坐标和纵坐标分开,必会存在两个相同的数,横纵坐标就 ...

  9. AtCoder题解 —— AtCoder Beginner Contest 187 —— B - Gentle Pairs —— 暴力

    题目相关 题目链接 AtCoder Beginner Contest 187 B 题,https://atcoder.jp/contests/abc187/tasks/abc187_b. Proble ...

最新文章

  1. Python在ubuntu中更改Python和pip指向
  2. oracle10g ora 29702,ORA-29702,请帮助一下。
  3. asp.net中使用窗体身份验证
  4. 软件测试工程师面试问题
  5. 小蚂蚁学习Redis笔记(13)——Redis之phpredis的安装
  6. 我改了500个Bug,但是!!
  7. 中艺人脸识别考勤机使用方法_人脸识别考勤机的使用方法及注意事项 - 全文
  8. 用python重构策略模式
  9. 数据科学和人工智能技术笔记 四、图像预处理
  10. React.js 官网入门教程 分离文件 操作无法正常显示HelloWord
  11. Java后端测试概述
  12. ELK logstash 处理MySQL慢查询日志
  13. 非root用户安装mysql_linux非root用户安装5.7.27版本mysql
  14. 联想x100e linux,联想小红ThinkPad X100e笔记本拆解!
  15. 2020上海大学生网络安全赛MISC题WP
  16. 新华财经•专访 | 来自大洋彼岸对区块链大势的深度解读
  17. 这只是起点 ——暨CSDN博客“我的2013”年度征文活动获得特等奖
  18. 小白学习java第11天多态抽象类接口
  19. 程序员对老板说:老子,明天不上班!结果...
  20. fullpage初使用

热门文章

  1. 上海交大暑期计算机培训,上海交通大学2018暑期学校报名通知
  2. java求最大公约数_java求最大公约数(分解质因数)
  3. java 中0x的数值表示方式 本质上是什么意思?
  4. mysql数据库权限赋予
  5. Facebook广告投放5种技巧
  6. uniapp微信客服
  7. 华为服务器 远程虚拟控制 如何连接
  8. 云计算、大数据和人工智能之间的关系----详细说明
  9. 计算机应用基础试题文件夹,计算机应用基础试题及参考答案
  10. ESP8266之TFT_eSPI库的自定义字体