The question is to establish a equations:
(Mat [1] [1] * x [1] + mat [1] [2] * x [2] +... + Mat [1] [n] * x [n]) % 7 = mat [1] [n + 1]
(Mat [2] [1] * x [1] + mat [2] [2] * x [2] +... + Mat [2] [n] * x [n]) % 7 = mat [2] [n + 1]
...
...
(Mat [m] [1] * x [1] + mat [m] [2] * x [2] +... + Mat [m] [n] * x [n]) % 7 = mat [m] [n + 1]
If there is a number of outputs to be parsed, if there is no Inconsistent data. Infinite Multiple sets of solutions Multiple solutions.
When is there no solution?
The rank of the coefficient matrix is not equal to the rank of the augmented matrix. Reflected in the program is:
For (I = row; I <N; I ++)
{
If (a [I] [M]! = 0)
{
Printf ("Inconsistent data. \ n ");
}
}
When is an infinite solution?
When the rank of the augmented matrix is smaller than the number of rows of the determinant. Reflected in the program is:
If (row <M)
{
Printf ("Multiple solutions. \ n ");
}
Well, the procedure is as follows:
# Include <cstdio> # include <cstring> # include <iostream> # include <cstdlib> using namespace std; int m, n; // n linesint M, N; int a [333] [333]; int times [333]; int ans [333]; int MOD = 7; int getday (char * s) {if (strcmp (s, "MON") = 0) return 1; if (strcmp (s, "TUE") = 0) return 2; if (strcmp (s, "WED ") = 0) return 3; if (strcmp (s, "THU") = 0) return 4; if (strcmp (s, "FRI") = 0) return 5; if (strcmp (s, "SAT") = 0) return 6; if (strcmp (s, "SUN ") = 0) return 7;} int extend_gcd (int A, int B, int & x, int & y) {if (B = 0) {x = 1, y = 0; return A;} else {int r = extend_gcd (B, A % B, x, y); int t = x; x = y; y = t-A/B * y; return r ;}} int lcm (int A, int B) {int x = 0, y = 0; return A * B/extend_gcd (A, B, x, y);} void Guass () {int I, j, row, col; for (row = 0, col = 0; row <N & col <M; row ++, col ++) {for (I = row; I <N; I ++) if (a [I] [col]) Break; if (I = N) {row --; continue;} if (I! = Row) for (j = 0; j <= M; j ++) swap (a [row] [j], a [I] [j]); for (I = row + 1; I <N; I ++) {if (a [I] [col]) {int LCM = lcm (a [row] [col], a [I] [col]); // remove the upper triangle int forward = LCM/a [row] [col], ch2 = LCM/a [I] [col]; for (j = col; j <= M; j ++) a [I] [j] = (a [I] [j] * ch2-a [row] [j] * Rows) % MOD + MOD) % MOD ;}}for (I = row; I <N; I ++) // no solution {if (a [I] [M]! = 0) {printf ("Inconsistent data. \ n "); return ;}}if (row <M) // infinite solution {printf (" Multiple solutions. \ n "); return ;}// for (I = M-1; I> = 0; I --) {int ch = 0; for (j = I + 1; j <M; j ++) {ch = (ch + ans [j] * a [I] [j] % MOD) % MOD;} int last = (a [I] [M]-ch) % MOD + MOD) % MOD; int x = 0, y = 0; int d = extend_gcd (a [I] [I], MOD, x, y); x % = MOD; if (x <0) x ++ = MOD; ans [I] = last * x/d % MOD; if (ans [I] <3) ans [I] + = 7 ;}for (int I = 0; I <M; I ++) {if (I = 0) printf ("% d", ans [I]); else printf ("% d", ans [I]);} printf ("\ n ");} int main () {while (scanf ("% d", & m, & n )! = EOF) {if (m = 0 & n = 0) break; M = m, N = n; memset (a, 0, sizeof ()); memset (times, 0, sizeof (times); memset (ans, 0, sizeof (ans); for (int I = 0; I <n; I ++) {int prodnum; char str1 [11], str2 [11]; scanf ("% d % s", & prodnum, str1, str2 ); for (int j = 0; j <prodnum; j ++) {int tmp; scanf ("% d", & tmp); a [I] [tmp-1] ++; a [I] [tmp-1] % = MOD;} a [I] [m] = (getday (str2)-getday (str1) + 1 + MOD) % MOD ;} guass ();} return 0 ;}