Holidays P92544


Statement
 

pdf   zip

Enric wants to go on holidays. He will first fly to any of nn cities. Let’s call cc that initial city. He will rent a car in cc, spend hh days on a roadtrip, and finally fly back home from cc. He can visit any city more than once in his route, but he will stay at least one day in each city he visits, everytime he visits it, with one exception: the first day he will not visit cc.

Given that he only cares about the order of the visited cities, but not about the number of days spent at every city, in how many ways can Enric plan his holidays? Apart from cc, he wants to visit at least another city. Consider that the travel time between cities is negligible.

Input

Input consists of several cases. Every case begins with nn and hh, followed by nn rows, one for every city ii, with nn numbers rijr_{ij} each, with a 1 if there is a direct road from city ii to jj, and a 0 otherwise. Note that roads may be one-way only, that is, the given adjacency matrix can be asymmetric. Assume 2n302 \le n \le 30, 1h1091 \le h \le 10^9, and rii=0r_{ii}=0.

Output

For every case, print the number of ways to spend hh days on holidays, modulo 109+12310^9 + 123.

Public test cases
  • Input

    3 2
    0 1 0
    0 0 1
    1 0 0
    
    3 2
    0 1 1
    0 0 1
    0 1 0
    
    4 4
    0 0 1 0
    1 0 0 1
    0 1 0 0
    0 1 0 0
    
    3 1000000
    0 1 1
    1 0 1
    1 0 0
    

    Output

    0
    2
    7
    137493254
    
  • Information
    Author
    Enric Cusell
    Language
    English
    Official solutions
    C++
    User solutions
    C++