diff --git a/Codes/1957 C - How Does the Rook Move/1957C.cpp b/Codes/1957 C - How Does the Rook Move/1957C.cpp new file mode 100644 index 0000000..a19b5f5 --- /dev/null +++ b/Codes/1957 C - How Does the Rook Move/1957C.cpp @@ -0,0 +1,51 @@ +#include +#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"<>=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>r>>c; + used += 2-(r==c); + } + int m=n-used; + int ans=func(m); + cout<> TC; + while (TC--) solve(); +} \ No newline at end of file diff --git a/Readme.md b/Readme.md index 6fa57a3..0886274 100644 --- a/Readme.md +++ b/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: + -
+## About Me :eyes: -## Index -#### Sorted by Problem ID -| Index | Problem ID | Problem Name | Question | Solution | -| :-----: | :--------: | :----------: | :------: | :------: | \ No newline at end of file +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. \ No newline at end of file