Garlic Jun received a birthday present - a box of beautiful crayons, which made him very happy. After completing a graph theory topic, Mr. Garantou took a crayon and wanted to color an undirected graph on the topic. There are a total of n on the undirected graph n points, numbered from 00 to n - 1n − 1 , then the graph will have 2^n - 12n −1 non-empty subgraphs.
Mr. Garlic wants to give every iColor the i subgraphs, so that the color of the two points connected by any edge is different, and now he wants to know how to give the iColoring of i sub-images, how many different colors are required at least, denoted as s_isi. Mr. Garantou would like to ask you to help him calculate the result of the following formula:
\displaystyle \sum_{i = 1}^{2^n-1} s_i \times 233^{i}.i=1∑2n−1si×233i.
input format
Enter an integer n on the first linen(1 \ leq n \ leq 161 ≤ n ≤ 1 6 ), indicating that the undirected graph has nn points.
Next enter a n \times nn × n 01 _ 0 1 matrix, representing the case of undirected graph edges. if a[i][j] = 1a [ i ] [ j ] = 1 , then ii give jThere are edges between j , if a[i][j] = 0a [ i ] [ j ] = 0 , it means ii give j There are no edges connected between j .
output format
Output a line, output the result of the above formula, the result may be very large, the output result is 2^{32}23 2 take the remainder of the result.
sample input
4 0111 1011 1101 1110
Sample output
1595912448
Problem-solving instructions: Initialize all subgraphs that are painted with only one color. Remember such a subgraph dp[i]=1; the subgraph with fewer nodes is to update the subgraph with all nodes,
dp[i]=min(dp[i],dp[j^i]+dp[j]); Add the coloring numbers of the two sub-atlases of the graph. For example, a picture such as 1-2-3-4-5-6, we will get dp[picture: 1-3-5]=1, dp[picture: 2-4-6]=1 during preprocessing
Then dp[1-2-3-4-5-6] will become 2 when updated;
Nothing to say, this question stuck me for a long time! The local is right, the online submission of the error indicates that there is a problem with oj! . . . . . I forgot the initial. Every round of i cycle mn needs to be set to infinity, heck.
AC code:
#include<iostream> #include<algorithm> #include<string.h> #include<cstdio> using namespace std; const int inf=0x3f3f3f3f; int dp[1<<16]; int a[20][20]; bool mark[1<<16]; unsigned int powdiy(int x,int y){ unsigned int re=1,be=x; while(y){ if(y&1)re*=be; be*=be; y>>=1; } return re; } void judge(int x){ int tot = 1; int cot=0; int note[20]; int temp=x; while(x){ if(x&1){ note[cot++]=tot; } x>>=1; to++; } for(int i=0;i<cot-1;i++) for(int j=i+1;j<cot;j++){ if(a[note[i]][note[j]]){ return ; } } dp[temp]=1; return ; } unsigned int sum=0; int main(){ int n;cin>>n; memset(dp,inf,sizeof(dp)); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++) scanf("%1d",&a[i][j]); } for(int i=1;i<(1<<n);i++){ judge(i); } for(int i=1;i<(1<<n);i++){ int mn=inf; for(int j=i;j;j=(j-1)&i){ dp[i]=min(dp[i],dp[j^i]+dp[j]); mn = min (dp [i], mn); } sum+=(mn*powdiy(233,i)); } cout<<sum<<endl; return 0; }