101832: [AtCoder]ABC183 C - Travel

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

There are $N$ cities. The time it takes to travel from City $i$ to City $j$ is $T_{i, j}$.

Among those paths that start at City $1$, visit all other cities exactly once, and then go back to City $1$, how many paths take the total time of exactly $K$ to travel along?

Constraints

  • $2\leq N \leq 8$
  • If $i\neq j$, $1\leq T_{i,j} \leq 10^8$.
  • $T_{i,i}=0$
  • $T_{i,j}=T_{j,i}$
  • $1\leq K \leq 10^9$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $K$
$T_{1,1}$ $\ldots$ $T_{1,N}$
$\vdots$
$T_{N,1}$ $\ldots$ $T_{N,N}$

Output

Print the answer as an integer.


Sample Input 1

4 330
0 1 10 100
1 0 20 200
10 20 0 300
100 200 300 0

Sample Output 1

2

There are six paths that start at City $1$, visit all other cities exactly once, and then go back to City $1$:

  • $1\to 2\to 3\to 4\to 1$
  • $1\to 2\to 4\to 3\to 1$
  • $1\to 3\to 2\to 4\to 1$
  • $1\to 3\to 4\to 2\to 1$
  • $1\to 4\to 2\to 3\to 1$
  • $1\to 4\to 3\to 2\to 1$

The times it takes to travel along these paths are $421$, $511$, $330$, $511$, $330$, and $421$, respectively, among which two are exactly $330$.


Sample Input 2

5 5
0 1 1 1 1
1 0 1 1 1
1 1 0 1 1
1 1 1 0 1
1 1 1 1 0

Sample Output 2

24

In whatever order we visit the cities, it will take the total time of $5$ to travel.

Input

题意翻译

### 题目描述 有 $n$ 个城市,从城市 $i$ 到城市 $j$ 需要的时间为 $t_{i,j}$。请问:从城市 $1$ 开始,只访问其他城市一遍,最后返回城市 $1$ 的路径中,有多少条路径所需要的时间为 $k$? ### 输入格式 输入共 $(n+1)$ 行。第一行输入两个正整数 $n,k$,中间以单个空格隔开;然后输入一个 $n \times n$ 的矩阵,第 $i$ 行第 $j$ 列上的数为 $t_{i,j}$。 ### 输出格式 输出一行一个非负整数,即满足条件的路径条数。 ### 说明/提示 #### 数据规模与约定 所有输入数据保证: - $2 \le n \le 8$; - 对于所有满足$1 \le i,j \le n$ 且 $i \neq j$ 的整数对 $(i,j)$,$t_{i,i}=0,t_{i,j}=t_{j,i},1 \le t_{i,j} \le 10^8$; - $1 \le k \le 10^9$; - 输入中的所有值均为整数。

加入题单

算法标签: