Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define oo 999999999
- #define MOD 1000000007
- #define MAXN 30
- int n;
- int a[MAXN][MAXN];
- int f[MAXN];
- int config[MAXN];
- int mpath;
- int cost;
- int eCost;
- int count;
- void input () {
- scanf("%d%d", &n, &eCost);
- mpath = oo;
- for (int i = 1; i <= n; ++i) {
- for (int j = 1; j <= n; ++j) {
- scanf("%d", &a[i][j]);
- if (a[i][j] < mpath && a[i][j] != 0) {
- mpath = a[i][j];
- }
- }
- f[i] = 0;
- }
- cost = 0;
- config[1] = config[n+1] = 1;
- f[1] = 1;
- count = 0;
- }
- bool check (int k, int v) {
- if (f[v]) {
- return false;
- }
- if (cost + a[config[k-1]][v] + mpath * (n+1-k) > eCost) {
- return false;
- }
- return true;
- }
- void update (int uCost) {
- ++count;
- // for (int i = 0; i <= n + 1; ++i)
- // printf("%d ", config[i]);
- // printf("\n");
- }
- void attempt (int k) {
- for (int v = 2; v <= n; ++v) {
- if (check(k, v)) {
- cost += a[config[k-1]][v];
- config[k] = v;
- f[v] = 1;
- if (k < n) {
- attempt(k+1);
- } else {
- if (cost + a[v][1] <= eCost) {
- update(cost + a[v][0]);
- }
- }
- f[v] = 0;
- cost -= a[config[k-1]][v];
- }
- }
- }
- void solve () {
- attempt(2);
- }
- void output () {
- printf("%d\n", count);
- }
- int main () {
- // freopen("inp", "r", stdin);
- // freopen("out", "w", stdout);
- input();
- solve();
- output();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement