SRM 531 div1 600

Source: Internet
Author: User

Good Graph Theory

[Cpp]
// BEGIN CUT HERE
 
// END CUT HERE
# Line 5 "MonsterFarm. cpp"
# Include <cstdlib>
# Include <cctype>
# Include <cstring>
# Include <cstdio>
# Include <cmath>
# Include <algorithm>
# Include <vector>
# Include <string>
# Include <iostream>
# Include <sstream>
# Include <map>
# Include <set>
# Include <queue>
# Include <stack>
# Include <fstream>
# Include <numeric>
# Include <iomanip>
# Include <bitset>
# Include <list>
# Include <stdexcept>
# Include <functional>
# Include <utility>
# Include <ctime>
Using namespace std;
 
Typedef long ll;
 
Class MonsterFarm
{
Public:
Int numMonsters (vector <string> transforms ){
Const int Mod = 1000000007;
Int g [51] [51], d [51], path [51] [51];
Int len, I, j, k;
Int n = transforms. size ();
Memset (g, 0, sizeof (g ));
Memset (d, 0, sizeof (d ));
Memset (path, 0, sizeof (path ));
For (I = 0; I <n; I ++ ){
Len = transforms [I]. size ();
Int tem = 0;
For (j = 0; j <len; j ++ ){
If (transforms [I] [j] = ''){
D [I] ++;
G [I] [tem-1] ++;
Path [I] [tem-1] = 1;
Tem = 0;
Continue;
}
Tem = tem * 10 + transforms [I] [j]-'0 ';
}
D [I] ++;
G [I] [tem-1] ++;
Path [I] [tem-1] = 1;
}
For (k = 0; k <n; k ++)
For (I = 0; I <n; I ++)
For (j = 0; j <n; j ++)
Path [I] [j] = (path [I] [j] | (path [I] [k] & path [k] [j]);
For (I = 0; I <n; I ++)
If (d [I]> = 2 & path [0] [I] & path [I] [I])
Return-1;
 
Ll num [2] [51];
Int cur = 0;
For (I = 0; I <n; I ++)
Num [cur] [I] = 0;
Num [cur] [0] = 1;
For (I = 0; I <n; I ++ ){
Cur ^ = 1;
For (j = 0; j <n; j ++) num [cur] [j] = 0;
For (j = 0; j <n; j ++)
For (k = 0; k <n; k ++)
Num [cur] [k] = (num [cur] [k] + num [cur ^ 1] [j] * g [j] [k]) % Mod;
}
Ll ans = 0;
For (I = 0; I <n; I ++)
Ans = (ans + num [cur] [I]) % Mod;
Return (int) ans;
}
 
// BEGIN CUT HERE
Public:
Void run_test (int Case) {if (Case =-1) | (Case = 0) test_case_0 (); if (Case =-1) | (Case = 1) test_case_1 (); if (Case =-1) | (Case = 2) test_case_2 (); if (Case =-1) | (Case = 3) test_case_3 (); if (Case =-1) | (Case = 4 )) test_case_4 (); if (Case =-1) | (Case = 5) test_case_5 ();}
Private:
Template <typename T> string print_array (const vector <T> & V) {ostringstream OS; OS <"{"; for (typename vector <T> :: const_iterator iter = V. begin (); iter! = V. end (); ++ iter) OS <'\ "' <* iter <" \ ","; OS <"}"; return OS. str ();}
Void verify_case (int Case, const int & Expected, const int & inclued) {cerr <"Test Case #" <Case <"... "; if (Expected = already ed) cerr <" PASSED "<endl; else {cerr <" FAILED "<endl; cerr <" \ tExpected: \ "" <Expected <'\ "' <endl; cerr <" \ tReceived: \ "" <Received <'\ "' <endl ;}}
Void test_case_0 () {string Arr0 [] = {"1"}; vector <string> Arg0 (Arr0, Arr0 + (sizeof (Arr0) /sizeof (Arr0 [0]); int Arg1 = 1; verify_case (0, Arg1, numMonsters (Arg0 ));}
Void test_case_1 () {string Arr0 [] = {"1 1"}; vector <string> Arg0 (Arr0, Arr0 + (sizeof (Arr0) /sizeof (Arr0 [0]); int Arg1 =-1; verify_case (1, Arg1, numMonsters (Arg0 ));}
Void test_case_2 () {string Arr0 [] = {"2", "3", "1"}; vector <string> Arg0 (Arr0, Arr0 + (sizeof (Arr0) /sizeof (Arr0 [0]); int Arg1 = 1; verify_case (2, Arg1, numMonsters (Arg0 ));}
Void test_case_3 () {string Arr0 [] = {"1", "3 4", "2", "2"}; vector <string> Arg0 (Arr0, arr0 + (sizeof (Arr0)/sizeof (Arr0 [0]); int Arg1 = 1; verify_case (3, Arg1, numMonsters (Arg0 ));}
Void test_case_4 () {string Arr0 [] = {"2 2", "3", "4 4 4", "5", "6 ", "7 7 7 7", "7"}; vector <string> Arg0 (Arr0, Arr0 + (sizeof (Arr0)/sizeof (Arr0 [0]); int Arg1 = 24; verify_case (4, Arg1, numMonsters (Arg0 ));}
Void test_case_5 () {string Arr0 [] = {"2 3", "5 7", "2 4", "5", "6", "4 ", "7"}; vector <string> Arg0 (Arr0, Arr0 + (sizeof (Arr0)/sizeof (Arr0 [0]); int Arg1 = 5; verify_case (5, arg1, numMonsters (Arg0 ));}
 
// END CUT HERE
 
}; Www.2cto.com
 
// BEGIN CUT HERE
Int main ()
{
MonsterFarm ___ test;
___ Test. run_test (-1 );
Return 0;
}
// END CUT HERE

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.