next_permutation

https://atcoder.jp/contests/abc302/tasks/abc302_c

#include <bits/stdc++.h>
#define ll long long
#define int long long
#define ull unsigned long long
#define vb v.begin()
#define ve v.end()
#define vc v.clear()
#define vs (int)v.size()
#define ss (int)s.size()
#define rs(i) resize(i)
#define ft first
#define sd second
#define inf 0x3f3f3f3f
#define P pair<int, int>
#define Pll pair<ll, ll>
#define Pis pair<int, string>
#define Psi pair<string, int>
#define Pic pair<int, char>
#define Pci pair<char, int>
#define forn(i, a, b) for (int i = a; i < b; i++)
#define fore(i, a, b) for (int i = a; i <= b; i++)
#define rofn(i, a, b) for (int i = a; i > b; i--)
#define rofe(i, a, b) for (int i = a; i >= b; i--)
#define Ios ios::sync_with_stdio(false), cin.tie(0)
const ll N = 2010;
const ll M = 100010;
const int INF = 2147483647;
using namespace std;

signed main()
{
	//Ios;
	int n, m;
	cin >> n >> m;
	vector<string> s(n);
	fore(i, 1, n)
	{
		cin >> s[i-1];
	}
	sort(s.begin(), s.end());
	do
	{
		bool ok = true;
		for (int i = 0; i < n - 1; i++) {
			int cnt = 0;
			for (int j = 0; j < m; j++) {
				if (s[i][j] != s[i + 1][j]) cnt += 1;
			}
			if (cnt != 1) ok = false;
		}
		if (ok) {
			cout << "Yes" << endl;
			return 0;
		}
	} while (next_permutation(s.begin(),s.end()));
	cout << "No" << endl;
	return 0;
}
/*
1
10
10 2 5 6 1 9 3 8 4 7
*/
/*******************************************
				  坤坤助我
............................................
............................................
............................................
............................................
.............................1ffLf1.........
............................GGGGGGGC........
....................8CCCftCCCCC1;LLG,.......
..................:CC8CCC.CCCCCCii..........
.................CC88CCCC.CCCCCCC...........
................CC88CCCCC .8.:8CCC..........
................888 CCCCC.88888G;;,.........
,................888CC88.888888888,.........
:::...............CCC888.888888888..........
:::::............Gi1tC8f888888C88,..........
:::::::,........111tttfffffLG8888...........
:::::::::,....ii111ttttttfffttG.............
::::::::::::i111tttffffffffffttt............
::::::::::11tttttfff....fffffftt ...........
..:::::::1Lf1tff,..........fffff1...........
....,:::iiftG::::::.........,LLGtL..........
::::::;:i11t:;;;;;;::,,,,,,,,, f1ii,::,,,,,,
::::::::i11t:::::::::::::::::::f111:::::::::
::::::::111:::::::::::::::::::::t111::::::::
:::::::i1if::::::,,,,,,,,,,,,,,:i111::::::,:
,,,,,::,8G,,,,,,,,,,,,,,,,,,,,,,,tL1:,,,,,,,
,,,,,,:LGL;,,,,,,,,,,,,,,,,,,,,,,,CLf,,,,,,,
,,,,,;LGGG,,,,:,,,,,,,,,,,,,,,,,,,LGCG,,,,,,

*******************************************/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值