added 1957C
This commit is contained in:
parent
47fba30140
commit
bb3c443352
51
Codes/1957 C - How Does the Rook Move/1957C.cpp
Normal file
51
Codes/1957 C - How Does the Rook Move/1957C.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include<bits/stdc++.h>
|
||||
#ifdef ONLINE_JUDGE
|
||||
#define dbg(...)
|
||||
#else
|
||||
#include "debug.h"
|
||||
#endif
|
||||
using namespace std;
|
||||
#define ll long long
|
||||
#define endl '\n'
|
||||
#define all(x) x.begin(), x.end()
|
||||
#define sz(x) (int)(x).size()
|
||||
#define yes cout<<"YES"<<endl
|
||||
#define no cout<<"NO"<<endl
|
||||
#define FAST (ios_base:: sync_with_stdio(false),cin.tie(NULL));
|
||||
ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;}
|
||||
|
||||
const int N=3e5+10, M=1e9+7;
|
||||
int dp[N];
|
||||
|
||||
int func(int n)
|
||||
{
|
||||
if(n==0 || n==1)
|
||||
return 1;
|
||||
if(dp[n]!=-1) return dp[n];
|
||||
dp[n]=(func(n-1)+(2ll*(n-1)*func(n-2))%M)%M;
|
||||
return dp[n];
|
||||
}
|
||||
void solve()
|
||||
{
|
||||
int n,k;
|
||||
cin>>n>>k;
|
||||
memset(dp,-1,sizeof(dp));
|
||||
int used=0;
|
||||
for(int i=0; i<k; ++i)
|
||||
{
|
||||
int r,c;
|
||||
cin>>r>>c;
|
||||
used += 2-(r==c);
|
||||
}
|
||||
int m=n-used;
|
||||
int ans=func(m);
|
||||
cout<<ans<<endl;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
FAST;
|
||||
int TC = 1;
|
||||
cin >> TC;
|
||||
while (TC--) solve();
|
||||
}
|
14
Readme.md
14
Readme.md
@ -302,16 +302,14 @@ This repository contains my solutions of Codeforces problems. They are in C++ la
|
||||
| 290 | 1956 C | Nene's Magical Matrix | [Question](https://codeforces.com/problemset/problem/1956/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1956%20C%20-%20Nene's%20Magical%20Matrix)
|
||||
| 291 | 1957 A | Stickogon | [Question](https://codeforces.com/problemset/problem/1957/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1957%20A%20-%20Stickogon)
|
||||
| 292 | 1957 B | A BIT of a Construction | [Question](https://codeforces.com/problemset/problem/1957/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1957%20B%20-%20A%20BIT%20of%20a%20Construction)
|
||||
| 293 | 1957 C | How Does the Rook Move | [Question](https://codeforces.com/problemset/problem/1957/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1957%20C%20-%20How%20Does%20the%20Rook%20Move)
|
||||
|
||||
# Codeforces Solutions
|
||||
|
||||
This repository contains my solutions of Codeforces problems. They are in C++ language.
|
||||
|
||||
#### If this repository helped you out, please consider giving it a :star:
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
## About Me :eyes:
|
||||
|
||||
## Index
|
||||
#### Sorted by Problem ID
|
||||
| Index | Problem ID | Problem Name | Question | Solution |
|
||||
| :-----: | :--------: | :----------: | :------: | :------: |
|
||||
I am Shazid Mashrafi.
|
||||
I am currently studying Computer Science and Engineering & trying to work my way up in the programming world.
|
||||
Visit my [Website](https://shazidmashrafi.com) and [Codeforces](https://codeforces.com/profile/ShazidMashrafi) account.
|
Loading…
Reference in New Issue
Block a user