给出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. 【旧文章搬运】ZwQuerySystemInformation枚举进线程信息

    原文发表于百度空间,2008-10-15========================================================================== 很古老的东 ...

  2. Android webkit 事件传递流程通道分析

    前言:基于android webview 上定制自己使用的可移植浏览器apk,遇到好多按键处理的问题.所以索性研究了一下keyevent 事件的传递流程. frameworks 层 keyevent ...

  3. django上课笔记4-复习数据库操作-复习模板-Seccion-详细cookie和session的区别

    一.复习数据库操作 字段类型 字符串 EmailField(CharField): IPAddressField(Field) URLField(CharField) SlugField(CharFi ...

  4. 【转】PL/SQL 使用技巧

    ref:http://blog.chinaunix.net/uid-21592001-id-3082675.html [转]plsql developer 使用技巧 Oracle数据库相信已成为很多企 ...

  5. C++经典面试题库 附带参考答案

    1.    面向对象的程序设计思想是什么? 答:把数据结构和对数据结构进行操作的方法封装形成一个个的对象. 2.    什么是类? 答:把一些具有共性的对象归类后形成一个集合,也就是所谓的类. 3.  ...

  6. hdoj1257【疑问】(贪心)

    这完全可以达到3*1e4个啊...如果这样子,这复杂度就炸了吧?... #include<iostream> #include<cstdio> #include<math ...

  7. 关于国债的一些计算: 理论TF价格2(缴款日前有付息)

    计算 ExpectedTFPrice 是一个比较复杂的计算,我们这里讨论复杂的一种情况. 给定一只可交割国债bond(一般为CTD),一个国债期货tf, 在t日(表示tf的一个交易日期,我们通过bon ...

  8. bzoj 3224: Tyvj 1728 普通平衡树【非旋treap】

    就是非旋treap的板子 #include<iostream> #include<cstdio> #include<cstdlib> using namespace ...

  9. 高级开发不得不懂的Redis Cluster数据分片机制

    Redis 集群简介 Redis Cluster 是 Redis 的分布式解决方案,在 3.0 版本正式推出,有效地解决了 Redis 分布式方面的需求. Redis Cluster 一般由多个节点组 ...

  10. 纯JS实现鼠标每隔一段时间才能让页面再次滚动

    这里没有用到浏览器的兼容性写法,只是提供思路(这里使用的是Google浏览器的方法) javascript代码部分: //获取html元素var oHtml =document.documentEle ...