Educational Codeforces Round 20 A

Description

You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.

One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.

If there exists no such matrix then output -1.

Input

The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).

Output

If the answer exists then output resulting matrix. Otherwise output -1.

Examples
input
2 1
output
1 0 
0 0
input
3 2
output
1 0 0 
0 1 0
0 0 0
input
2 5
output
-1
题意:问如何将二进制矩阵排成字典序最大(需要主对角线对称)
解法:当然是这种啦,如果发现还有剩余1就输出-1
1 1 1 1 1 1 1 1 1...
1 1
1 1
1 .
1 .
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 const int maxn=654321;
 5 int x[200][200];
 6 int n;
 7 int num;
 8 int main()
 9 {
10     cin>>n>>num;
11     for(int i=1;num>0&&i<=n;i++)
12     {
13         x[i][i]=1;
14         num--;
15         for(int j=i+1;num>1&&j<=n;j++)
16         {
17             x[i][j]=x[j][i]=1;
18             num-=2;
19         }
20     }
21     if(num>0)
22     {
23         cout<<"-1"<<endl;
24         return 0;
25     }
26     for(int i=1;i<=n;i++)
27     {
28         for(int j=1;j<=n;j++)
29         {
30             cout<<x[i][j]<<" ";
31         }
32         cout<<endl;
33     }
34     return 0;
35 }
原文地址:https://www.cnblogs.com/yinghualuowu/p/6792572.html