给出N*M矩阵,对于该矩阵有两种操作:
1.交换两列,对于整个矩阵只能操作一次
2.每行交换两个数。
交换后是否可以使每行都递增。
*解法:N与M均为20,直接枚举所有可能的交换结果,进行判断
每次枚举注意列和行都可以选择不交换
#include <iostream>
#include <cstdio>
using namespace std;
int n, m;
int a[][];
bool check(int t)//检查第t行是否符合递增
{
int flag = ;
for(int i = ; i < m; i++)
if(a[t][i] < a[t][i - ]) {flag = ; break;}
if(!flag) return false;
return true;
}
void swapcolumn(int x, int y)//交换两列
{
int tmp[];
for(int i = ; i < n; i++)
{
tmp[i] = a[i][x];
a[i][x] = a[i][y];
a[i][y] = tmp[i];
}
return;
}
int main()
{
scanf("%d %d", &n, &m);
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
scanf("%d", &a[i][j]);
int flag[], ff = , res = ;
for(int i = ; i < n; i++) flag[i] = ;
for(int p = ; p < m; p++)
{
for(int q = p; q < m; q++)
{
for(int i = ; i < n; i++) flag[i] = ;
ff = ;
swapcolumn(p, q);
for(int t = ; t < n; t++)
{
for(int i = ; i < m; i++)
{
for(int j = i; j < m; j++)
{
swap(a[t][i], a[t][j]);
if(check(t)) flag[t] = ;
swap(a[t][i], a[t][j]);//如果这两个交换不行,就把它俩换回来
}
}
}
for(int i = ; i < n; i++)
if(!flag[i]) {ff = ; break;}
if(ff) res = ;//res记录最终结果
swapcolumn(p, q);
}
}
if(!res) printf("NO\n");
else printf("YES\n");
return ;
}

枚举 || CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution的更多相关文章

  1. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  2. Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution —— 异或

    题目链接:http://codeforces.com/contest/742/problem/B B. Arpa's obvious problem and Mehrdad's terrible so ...

  3. Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution

    B. Arpa’s obvious problem and Mehrdad’s terrible solution time limit per test 1 second memory limit ...

  4. 【codeforces 742B】Arpa’s obvious problem and Mehrdad’s terrible solution

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. Arpa’s obvious problem and Mehrdad’s terrible solution 思维

    There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious ...

  6. B. Arpa’s obvious problem and Mehrdad’s terrible solution

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  7. CF742B Arpa's obvious problem and Mehrdad's terrible solution 题解

    Content 有一个长度为 \(n\) 的数组,请求出使得 \(a_i \oplus a_j=x\) 且 \(i\neq j\) 的数对 \((i,j)\) 的个数.其中 \(\oplus\) 表示 ...

  8. codeforces 741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths(启发式合并)

    codeforces 741D Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths 题意 给出一棵树,每条边上有一个字符,字符集大小只 ...

  9. codeforces 741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths

    题目链接:Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths 第一次写\(dsu\ on\ tree\),来记录一下 \(dsu\ o ...

随机推荐

  1. 数据类型总结 (C++)

    数据类型总结 (C++) 作用 C++ 大小 取值范围 后缀 字符 char 1 -128~127   字符(无符号) unsigned char 1 0~255   宽字符 wchar_t 2   ...

  2. 09_多线程下载_获取文件长度&计算下载范围

    package com.itheima.multiThreadDownload; //import java.net.MalformedURLException; import java.io.Ran ...

  3. 死记硬背之Bunside

    就是 本质不同的个数为 $$\frac{1}{|G|} \cdot \sum_{|s| \in |G|}{ C(|s|) }$$ 所以,虽然不知道为啥,但是等价类的个数为 $$\sum_{i=1}^{ ...

  4. 任务37:生成 JWT Token

    实现给用户办法token 默认是可以访问valuesController的,返回的状态是200 http://localhost:5429/api/values 返回的状态码是200 把ValuesC ...

  5. sql server2008配置管理工具服务显示远程过程调用失败

    SQL SERVER2008配置管理工具服务显示远程过程调用失败   前两天,装了VS2012后,打开SQL2008配置管理工具,发现SQL服务名称里什么也没有,只有一个提示:(如图) 上网搜了,试了 ...

  6. JAVA基础-面向对象07

    一.代码块 1. 含义: 就是使用大括号括起来的一段代码 格式 { 代码: } 2.静态代码块 格式 static{ 代码: } 书写位置: 直接书写在类中成员位置: 怎么执行呢? 在类加载的最后一步 ...

  7. 洛谷 - P2293 - 高精度开根 - 高精度

    https://www.luogu.org/problemnew/show/P2293 要求求出给定高精度整数的非负根取整的结果. 还有神仙用Python的浮点pow运算骗到不少分的. 唉! 那么我们 ...

  8. 枚举与#define 宏的区别

    1),#define 宏常量是在预编译阶段进行简单替换.枚举常量则是在编译的时候确定其值.2),一般在编译器里,可以调试枚举常量,但是不能调试宏常量.3),枚举可以一次定义大量相关的常量,而#defi ...

  9. PTA 朋友圈【并查集的合并问题】

    一开始,考虑的是每次就是把第一个作为祖先,这样很明显是错误的,比如 7 4 3 1 2 3 2 4 2 3 5 6 7 1 6 所以这正是更好地体现对于集合的代表.只有把所有的元素合并一下,然后选一个 ...

  10. P5167 xtq的神笔

    传送门 题解 倍增也好二分也好,果然复杂度只要和\(\log\)插上关系就没我啥事了-- 首先由一个显而易见然而我完全没有发现的结论,设\(calc(l,r)\)表示区间\([l,r]\)的\(or\ ...