首页 > 其他分享 >[AtCoder] B - Counting Grids

[AtCoder] B - Counting Grids

时间:2023-03-21 23:44:19浏览次数:44  
标签:AtCoder Grids get ways there number same numbers Counting

 

 

The key observation is that there is always at most 1 cell that violates both conditions. 

Proof: 

if x violates both conditions, that means all other numbers on the same column < x and all other nubmers on the same row > x, so we have u < x && v > x.

if there is another violating cell, by definition, it can not be on the same row or the same column with x, so have the following diagram. similarly we have u > y && v < y.

using x's info we have u < v; using y's info we have u > v, contradiction!

 

 

 

With the above observation, we iterate over all the possible violating numbers and for each such number X, we do the following calculation to get the number of invalid ways.

1. pick a cell, there are N * N possible spots.

2. For each spot, pick N - 1 numbers < X and get their permutation count; do the same for > X. 

3. For the remaining unfilled cells, there are (N * N - (N * 2 - 1))! possible ways.

4. multiply the results from step 1-3 to get the total number of invalid ways for a single violating number X.

 

Subtract the sum of all invalid ways from (N^2)! to get the final answer.

 

标签:AtCoder,Grids,get,ways,there,number,same,numbers,Counting
From: https://www.cnblogs.com/lz87/p/17242098.html

相关文章

  • AtCoder Beginner Contest 294
    题解报告基本的一些理解和问题都在注释中A:Filter//水题#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>usingnamespacestd;intm......
  • [??记录] AtCoder 练习
    3.19arc066_c(dp,观察)观察:只会在负号右边添加\((/)\)两个位置之间至多一个括号。括号不会嵌套多层。\(f[i][j]\)表示处理完\(i\)个数,有\(j\)个未匹配左括号......
  • AtCoder Beginner Contest 294
    A-Filter(abc294a)题目大意给定一个数组,不改变原顺序,输出是偶数的数。解题思路模拟即可。神奇的代码#include<bits/stdc++.h>usingnamespacestd;usingLL......
  • AtCoder Beginner Contest 293
    A-SwapOddandEven#include<bits/stdc++.h>usingnamespacestd;int32_tmain(){ strings; cin>>s; for(inti=0;i+1<s.size();i+=2) swap(......
  • AtCoder Beginner Contest 293
    上周因为GDKOI咕咕咕了A-SwapOddandEven(abc293a)题目大意给定一个字符串,交换每两个相邻字母,输出结果。解题思路模拟即可。神奇的代码#include<bits/std......
  • AtCoder Beginner Contest 293(C,D ,E,F)
    AtCoderBeginnerContest293(C,D,E,F)CC这道题其实还蛮好写的,就是一个\(dfs\),然后我看错了题意,就记录一下这道题的大意是我们需要从\((1,1)\)走到\((n,m)\),我们只......
  • [AtCoder Beginner Contest 281][G. Farthest City]
    和CF1657E的做法十分相似题目链接:G-FarthestCity题目大意:问有多少个\(n(3\len\le500)\)个点的无向连通图满足,若设\(1\)到\(i\)的最短路距离为\(dis_i\),则......
  • AtCoder Regular Contest 158
    Preface这场比赛刚好周日晚上没事就打了,堪堪混过三道题,也算是小上了一波分吧但是由于A题脑抽了一波卡了30min,导致排名不高,也没时间看DE了,属实有点可惜A-+3+5+7显......
  • P3605 [USACO17JAN]Promotion Counting P
    求某节点子树内比该节点的点权大的点的个数 值域上维护树状数组,#include<bits/stdc++.h>usingnamespacestd;constintN=1e5+2,M=N*2;intbin[N],len;......
  • AtCoder Beginner Contest 293
    题解报告基本的一些理解和问题都在注释中A:SwapOddandEven//水题#include<cstdio>#include<algorithm>#include<iostream>#include<cstring>usingnamespace......