#include<iostream> #include<cstring> constint MOD = 1000000007; using std::cin; using std::cout; using std::cerr; using std::endl; using std::min; using std::max; int dp[2][101], a[101][101], n, m; intmain(){ cin >> n >> m; dp[1][0] = 1; // cin.get(); char c; for (registerint i = 1; i <= m; ++i){ dp[1][i] = 1; for (registerint j = 1; j <= m; ++j){ cin >> c; a[i][j] = c - '0'; } } int cur = 0, prev = 1; for (registerint i = 2; i <= n; ++i){ for (registerint j = 0; j <= m; ++j){ dp[cur][j] = 0; for (registerint k = 0; k <= m; ++k){ if (a[j][k]) continue; dp[cur][j] += dp[prev][k]; dp[cur][j] %= MOD; } } std::swap(cur, prev); } int ans = 0; for (int i = 0; i <= m; ++i){ ans += dp[prev][i]; ans %= MOD; } cout << ans; return0; }
#include<iostream> #include<cstring> typedeflonglong LL; constint MOD = 1000000007; using std::cin; using std::cout; using std::cerr; using std::endl; using std::min; using std::max; int n, m; structmatrix{ int a[110][110], m, n; voidinit(constint &nM, constint &nN){ std::memset(this->a, 0, sizeof(this->a)); this->m = nM; this->n = nN; } matrix operator=(const matrix &s){ this->init(s.m, s.n); for (int i = 0; i <= s.m; ++i) for (int j = 0; j <= s.n; ++j) this->a[i][j] = s.a[i][j]; return *this; } matrix operator*(const matrix &s){ matrix ans; ans.init(this->m, s.n); for (int i = 1; i <= this->m; ++i){ for (int j = 1; j <= s.n; ++j){ for (int k = 1; k <= this->n; ++k){ ans.a[i][j] += (LL)this->a[i][k]%MOD*(LL)s.a[k][j]%MOD; ans.a[i][j] %= MOD; } } } return ans; } }A, B; std::ostream& operator<<(std::ostream &out, const matrix &s){ for (int i = 1; i <= s.m; ++i){ out << '['; for (int j = 1; j <= s.n-1; ++j){ out << s.a[i][j] << ' '; } out << s.a[i][s.n]; out << "]\n"; } return out; } intmain(){ cin >> n >> m; char c; A.init(m+1,m+1); for (registerint i = 1; i <= m; ++i){ A.a[i][m+1] = 1; for (registerint j = 1; j <= m; ++j){ cin >> c; A.a[i][j] = c - '0'; A.a[i][j] ^= 1; } } for (registerint i = 1; i <= m+1; ++i){ A.a[m+1][i] = 1; } B.init(m+1,m+1); B = A; int p = n-2; while (p > 0){ if (p%2!=0) B = B*A; A = A*A; p /= 2; } matrix ans; ans.init(1, m+1); for (int i = 1; i <= ans.n; ++i) ans.a[1][i] = 1; ans = ans * B; int sum = 0; for (int i = 1; i <= ans.n; ++i){ sum += ans.a[1][i]; sum %= MOD; } cout << sum; return0; }