Skip to content
Snippets Groups Projects
Commit 28aa41dc authored by 김시환's avatar 김시환
Browse files

22.05.12

parent 1f185f4e
Branches master
No related tags found
No related merge requests found
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int ans;
int check[11];
int player[11][11];
void back(int play, int sum)
{
if(play == 11)
{
ans = max(ans, sum);
return;
}
for(int i=0;i<11;i++)
{
if(player[play][i] != 0 && check[i] == 0)
{
check[i] = 1;
back(play+1, sum + player[play][i]);
check[i] = 0;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
while(T--)
{
ans = 0;
for(int i=0;i<11;i++)
for(int j=0;j<11;j++)
cin >> player[i][j];
back(0, 0);
cout << ans << "\n";
}
}
\ No newline at end of file
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
void back(int idx, string str, int len)
{
if(idx == len - 1)
{
cout << str << "\n";
return;
}
for(int i=idx;i<len;i++)
{
if(i != idx && str[i] == str[idx])
continue;
if(str[i] != str[idx])
swap(str[i], str[idx]);
back(idx+1, str, len);
}
}
int main()
{
int t;
cin >> t;
while(t--)
{
string in;
cin >> in;
sort(in.begin(), in.end());
back(0, in, in.size());
}
}
\ No newline at end of file
#include<iostream>
#include<vector>
using namespace std;
int N, ans;
int board[16][16];
bool check(int x, int y)
{
for(int i = 0; i<N;i++)
if(board[x][i] == 1 || board[i][y] == 1)
return false;
for(int i=x, j=y;i>=0 && j>=0;i--,j--)
if(board[i][j] == 1)
return false;
for(int i=x, j=y;i>=0 && j<N;i--,j++)
if(board[i][j] == 1)
return false;
return true;
}
void back(int idx)
{
if(idx == N)
{
ans++;
return;
}
for(int i=0;i<N;i++)
if(check(idx,i) == true)
{
board[idx][i] = 1;
back(idx + 1);
board[idx][i] = 0;
}
}
int main()
{
cin >> N;
back(0);
cout << ans;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment