日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Problem - 4828 Grids

發布時間:2024/4/18 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Problem - 4828 Grids 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接

Problem Description

  度度熊最近很喜歡玩游戲。這一天他在紙上畫了一個2行N列的長方形格子。他想把1到2N這些數依次放進去,但是為了使格子看起來優美,他想找到使每行每列都遞增的方案。不過畫了很久,他發現方案數實在是太多了。度度熊想知道,有多少種放數字的方法能滿足上面的條件?

Input

  第一行為數據組數T(1<=T<=100000)。  然后T行,每行為一個數N(1<=N<=1000000)表示長方形的大小。

Output

  對于每組數據,輸出符合題意的方案數。由于數字可能非常大,你只需要把最后的結果對1000000007取模即可。

Sample Input

2
1
3

Sample Output

Case #1:
1
Case #2:
5
Hint
對于第二組樣例,共5種方案,具體方案為:

AC

  • 卡特蘭樹板子題
#include <iostream> #include <stdio.h> #include <map> #include <math.h> #include <vector> #include <algorithm> #include <cmath> #include <cstring> #define ll long long #define N 1000005 #define mem(a, b) memset(a, b, sizeof(a)) #define P pair<int, int> #define pb push_back using namespace std;ll mod = 1e9 + 7; ll f[N]; ll exgcd(ll a, ll b, ll &x, ll &y) {ll d = a;if (b == 0) {x = 1;y = 0;}else {d = exgcd(b, a % b, y, x);y -= a / b * x;}return d; }ll inv(ll a) {ll x, y;ll d = exgcd(a, mod, x, y);if (d != 1)return -1;elsereturn (x % mod + mod) % mod; } int main() { #ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout); #endiff[1] = 1;for (int i = 2; i < N; ++i) {f[i] = (f[i - 1] * (4 * i - 2)) % mod;f[i] *= inv(i + 1);f[i] %= mod;}int t;scanf("%d", &t);for (int i = 1; i <= t; ++i) {int n;scanf ("%d", &n);printf("Case #%d:\n%lld\n", i, f[n]);}#ifndef ONLINE_JUDGEfclose(stdin);fclose(stdout);system("leafpad out.txt"); #endifreturn 0; }

總結

以上是生活随笔為你收集整理的Problem - 4828 Grids的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。