给出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. java web url编码解码问题(下载中文名文件)

    问题描述:需要url直接访问中文名的文件,类似于在地址栏里直接输入http://localhost:8080/example/丽江旅游攻略.doc 来进行文件下载,tomcat的server.xml文 ...

  2. Tomcat | 修改默认端口

    Tomcat安装目录下 conf 目录下 server.xml 找到 <Connector connectionTimeout="/> 修改其中port值即可

  3. 【bzoj2084】[Poi2010]Antisymmetry

    2084: [Poi2010]Antisymmetry Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 1205  Solved: 756[Submit ...

  4. D Tree HDU - 4812

    https://vjudge.net/problem/HDU-4812 点分就没一道不卡常的? 卡常记录: 1.求逆元忘开longlong 2.把solve中分离各个子树的方法,由“一开始全部加入,处 ...

  5. 第02课 操作系统及Linux 系统介绍

    1.操作系统介绍 操作系统(Operating System,简称OS),是计算机系统中必不可少的基础系统软件,它是应用程序运行以及用户操作必备的基础环境支撑,是计算机系统的核心. 操作系统的作用是管 ...

  6. IIR型高斯滤波的原理及实现

    二.实现 GIMP中有IIR型高斯滤波的实现,代码位于contrast-retinex.c中,读者可自行查看.下面给出本人实现的核心代码: #include"stdafx.h" t ...

  7. 如何正确从他人机器MySQL数据库下拷贝出.sql,再导入到自己windows下MySQL数据库(图文详解)

    不多说,直接上干货! 我这里,是放在桌面上. 登陆数据库 然后, mysql -uroot -p 默认是回车. 创建数据库 CREATE DATABASE securityonion_db; 目的,就 ...

  8. MySQL读写分离实现

    数据库写入效率要低于读取效率,一般系统中数据读取频率高于写入频率,单个数据库实例在写入的时候会影响读取性能,这是做读写分离的原因.实现方式主要基于mysql的主从复制,通过路由的方式使应用对数据库的写 ...

  9. LN : leetcode 215 Kth Largest Element in an Array

    lc 215 Kth Largest Element in an Array 215 Kth Largest Element in an Array Find the kth largest elem ...

  10. windows下常用的一些shell命令

    看的视频上都是linux系统的shell命令,和windows区别很多.所以整理了windows常用的一些shell命令. 注意:并不是每个都试验过,使用时还需自己验证下. 学system和os,su ...