2015-2016-petrozavodsk-winter-training-camp-spb-su-spb-au-contest F-Colored Path(状压DP)

题面:

Colored Path

									Time limit: 1.5 seconds
								  Memory limit: 256 mebibytes

Problem Description

You have a board of size n × n. Each cell of the board has weight and color. Both weight and color are
positive integers. Rows and columns are enumerated from 1 to n. Let (i, j) be j-th cell of i-th row. In one
step you can move from cell (i, j) to cells (i, j + 1) and (i + 1, j).

Consider all paths from (1, 1) to (n, n) that obey the rule above. Obviously each such path contains
exactly 2n − 1 cells. Let’s define the weight of the path as the sum of the weights of the cells on the path.
Let’s define the colorness of the path as the number of different colors among the colors of the cells on
the path.

Given the weights and the colors of all cells, find the smallest colorness among all paths with weight no
more than W or report that there are no such paths.

Input

The first line contains three integers: n (1 ≤ n ≤ 400), k (1 ≤ k ≤ 10) which is the number of possible
colors, and W (1 ≤ W ≤ 1 0 9 10^9 109). Each of the next n lines contains n integers, j-th integer on i-th line is the
weight of the cell (i, j) (1 ≤ w i j w_{ij} wij 1 0 6 10^6 106). The last n lines contain n integers each, j-th integer on i-th line
is the color of the cell (i, j) (1 ≤ c i j c_{ij} cij ≤ k).

Output

On the first line output the minimal colorness of the path. On the second line output the path with
the minimal colorness in the format i 1 i_1 i1 j 1 j_1 j1 i 2 i_2 i2 j 2 j_2 j2 . . . i 2 n − 1 i_{2n−1} i2n1 j 2 n − 1 j_{2n−1}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值