#include <iostream> using namespace std; int n,m, a[10]; void DFS(int k) { if (k>n) { for (int i=1; i<=n; i++) cout<<a[i]<<" "; cout<<endl; } else for (int i=0; i<=1; i++) { a[k]=i; DFS(k+1); } } int main() { cin>>n; DFS(1); return 0; }
#include <iostream> using namespace std; #define N 20 int b[N],t,n; int main(int argc, char *argv[]) { int x,i,t; cin>>n; for (x=0;x<=(1<<n)-1;x++) { t=x; for (i=0;i<n;i++) { b[i]=t%2 ;t/=2; } for (i=0;i<n;i++) cout<<b[i]<<" "; cout<<endl; } return 0; }
#include <iostream>
using namespace std;
#define N 20 int b[N],t,n;
int main(int argc, char *argv[])
{ int x,i,t;
cin>>n;
for (x=0;x<=(1<<n)-1;x++)
{ t=x;
for (i=0;i<n;i++) { b[i]=t%2 ;t/=2; }
for (i=0;i<n;i++)
cout<<b[i]<<" "; cout<<endl;
}
return 0;
}
#include <iostream> using namespace std; #define N 20 int g[N][N],b[N],t,n; void input() { int i,j,f,t; cin>>n; for(i=0;i<n;i++) for(j=0;j<n;j++) cin>>g[i][j]; } int main(int argc, char *argv[]) { int x,i,j,t,ans,sum; input(); ans=0; for(x=0;x<=(1<<n)/2;x++) { t=x; for(i=0;i<n;i++) { b[i]=t%2 ; t/=2; } for(i=0;i<n;i++) sum=0; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(b[i]!=b[j]) sum +=g[i][j]; if(sum>ans) ans=sum; } //for(i=0;i<n;i++) // cout<<b[i]<<" "; // cout<<endl; cout<<ans<<" "; cout<<endl; return 0; }
#include <iostream>
using namespace std;
#define N 20
int g[N][N],b[N],t,n;
void input()
{ int i,j,f,t;
cin>>n;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
cin>>g[i][j];
}
int main(int argc, char *argv[])
{
int x,i,j,t,ans,sum;
input();
ans=0;
for(x=0;x<=(1<<n)/2;x++)
{ t=x;
for(i=0;i<n;i++) { b[i]=t%2 ; t/=2; }
for(i=0;i<n;i++) sum=0;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(b[i]!=b[j]) sum +=g[i][j];
if(sum>ans) ans=sum;
}
cout<<ans<<" "; cout<<endl;
return 0;
}