Codeforces 57C Array dp暴力找规律

题目链接:点击打开链接

先是计算非递增的方案,

若非递增的方案数为x, 则非递减的方案数也是x

答案就是 2*x - n

只需求得x即可。

可以先写个n3的dp,然后发现规律是 C(n-1, 2*n-1)

然后套个逆元即可。

#include<iostream>
#include<cstdio>
#include<vector>
#include<string.h>
using namespace std;
#define ll long long
#define mod 1000000007
ll n;
ll Pow(ll x, ll y)
{
    ll ans = 1;
    while(y)
    {
        if(y&1) ans = (ans * x) % mod;
        y >>= 1;
        x = (x*x)%mod;
    }
    return ans;
}
ll chu(ll x, ll y)
{
    return (x * Pow(y, mod-2))%mod;
}
int main(){
	ll i, j;
	while(cin>>n){
        if(n==1){puts("1");continue;}
        n -- ;
        ll ans = n+2;
        ll zi = 2, mu = n+3;
        for(i = n+3; i <= 2*n+1; i++)
        {
            ans *= mu;
            ans = chu(ans % mod, zi);
            mu++; zi++;
        }
        ans *= 2; ans -= (n+1);
        ans += mod;
        cout<<ans%mod<<endl;
	}
	return 0;
}

Codeforces 57C Array dp暴力找规律

时间: 2024-08-10 23:21:35

Codeforces 57C Array dp暴力找规律的相关文章

Codeforces 57C Array dp暴力找到规律

主题链接:点击打开链接 的非增量程序首先,计算, 如果不增加的节目数量x, 非减少一些方案是x 答案就是 2*x - n 仅仅需求得x就可以. 能够先写个n3的dp,然后发现规律是 C(n-1, 2*n-1) 然后套个逆元就可以. #include<iostream> #include<cstdio> #include<vector> #include<string.h> using namespace std; #define ll long long #

ACM_同余+暴力找规律

小光的忧伤 Time Limit: 2000/1000ms (Java/Others) Problem Description: 锴神:我尊重作者原意,你们出什么我就加什么.于是小光打了道水题(也就是这道),但是呢比赛的时候拿着自己的标程却AC不了,最后只能尴尬地打表!!为毛呢?!请你来看看这道题,为了缓解小光的尴尬,他决定不告诉你样例输入输出,神马?!没有输入输出?对,就是这么贼! Input: 多组数据,输入n,求(1^n+2^n+3^n+4^n)mod 5,其中n范围是[10^5,10^(

Codeforces Gym 100637B B. Lunch 找规律

B. Lunch Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/B Description The swamp looks like a narrow lane with length n covered by floating leaves sized 1, numbered from 1 to n with a fly sitting on the top of ea

POJ 2663 Tri Tiling dp 画图找规律

状态:d[i]代表n=i时的方案数. 状态转移方程:d[i]=d[i-2]+2*(d[i-2]+d[i-4]+…+d[0]) i只会为偶数,奇数情况不存在,d[0]=1 找状态转移方程的时候画图更好理解. #include <iostream> #include <cstdio> #include <algorithm> using namespace std; int d[50]; int main() { int n; d[0]=1; d[2]=3; int sum

CodeForces 57C Array 组合计数+逆元

题目链接: http://codeforces.com/problemset/problem/57/C 题意: 给你一个数n,表示有n个数的序列,每个数范围为[1,n],叫你求所有非降和非升序列的个数. 题解: 由于对称性,我们只要求非降序的个数就可以了(n个数全部相等的情况既属于非升也属于非降) 我们在满足条件的n个数之前加一个虚节点1,在第n个数之后加一个n,那么考虑这n+2个数组成的非降序列: 假设序列里的第i个数为a[i],我们设xi=a[i+1]-a[i]+1,1<=i<=n+1,则

BZOJ 1002 FJOI 2007 轮状病毒 暴力+找规律+高精度

题目大意: 思路:基尔霍夫矩阵求生成树个数,不会. 但是可以暴力打表.(我才不会说我调试force调试了20分钟... CODE(force.cc): #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 1000 using namespace std; struct Edge{ int x,y; Edge(int _,int __

HDU - 4722 Good Numbers 【找规律 or 数位dp模板】

If we sum up every digit of a number and the result can be exactly divided by 10, we say this number is a good number. You are required to count the number of good numbers in the range from A to B, inclusive. InputThe first line has a number T (T <=

[FJOI2007]轮状病毒 题解(dp(找规律)+高精度)

[FJOI2007]轮状病毒 题解(dp(找规律)+高精度) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1335733 没什么好说的,直接把规律找出来,有两种规律(据说还有多种dp),再套个高精度 \(First\) \(f[1]=1,f[2]=5,f[i]=3×f[i-1]-f[i-2]+2\) 就直接写个高精+低精和高精×低精和高精-高精就行了 \(Second\) \(f[1]=1,f[2]=3,f[i]=f[i-1]+f[i-2]\) \(i

hdu 2147 kiki&#39;s game(DP(SG)打表找规律)

题意: n*m的棋盘,一枚硬币右上角,每人每次可将硬币移向三个方向之一(一格单位):左边,下边,左下边. 无法移动硬币的人负. 给出n和m,问,先手胜还是后手胜. 数据范围: n, m (0<n,m<=2000) 思路: dp[i][j]=0,说明从(i,j)这个点到时左下角先手败.dp[i][j]=1则先手胜. 然后记忆搜.但是记忆搜会超时. 搜完把整张表打出来,发现规律了,,,,然后,,,代码剩几行了. 代码: ///打表观察 /* int f[2005][2005]; int go(in