ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

某暑假集训F

2022-08-07 22:02:19  阅读:154  来源: 互联网

标签:__ const int res 暑假 return include 集训


给出n和k,然后构建长度为n最大数不超过k的非递减数列,要消耗的力量为序列的最大值,那么构建所有的序列需要消耗的总力量是多少

#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<unordered_map>
// #pragma GCC optimize(3)
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define scan(x)   scanf("%lld",&x)
#define int long long
#define lowbit(x) x&(-x)
#define PI 3.1415926535
typedef pair<int,int> PII;
int gcd(int a,int b){
    return b>0 ? gcd(b,a%b):a;
}
const int N = 1e6+10;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
void init()
{
    cin.tie(0),cout.tie(0);
    ios::sync_with_stdio(false);
}

int n,k,fact[N],infact[N];

int qmi(int a,int b,int p)
{
    int res = 1%p;
    while(b)
    {
        if(b&1)res = res * a % p;
        a = a * a % p;
        b>>=1;
    }
    return res;
}

int C(int a,int b)
{
    return fact[a]*infact[a-b]%mod*infact[b]%mod;
}

void solve()
{
    int ans = 1;
    int res = 0;
    for(int i=1;i<=k;i++)
    {
        ans = C(i+n-1,i)*i%mod;
        res+=ans; 
    }
    cout<<res%mod<<endl;
}

signed main()
{
    init();
    
    infact[0]=fact[0]=1;
    
    for(int i=1;i<=N;i++)
    {
        infact[i]=infact[i-1]*qmi(i,mod-2,mod)%mod;
        fact[i]=fact[i-1]*i%mod;
    }
    
    cin>>n>>k;
    
    solve();
    

    
}

















































































//                              _ooOoo_
//                             o8888888o
//                             88" . "88
//                             (| -_- |)
//                              O\ = /O
//                           ____/`---'\____
//                        .   ' \\| |// `.
//                         / \\||| : |||// \
//                        / _||||| -:- |||||- \
//                         | | \\\ - /// | |
//                       | \_| ''\---/'' | |
//                        \ .-\__ `-` ___/-. /
//                    ___`. .' /--.--\ `. . __
//                  ."" '< `.___\_<|>_/___.' >'"".
//                 | | : `- \`.;`\ _ /`;.`/ - ` : | |
//                    \ \ `-. \_ __\ /__ _/ .-` / /
//           ======`-.____`-.___\_____/___.-`____.-'======
//                              `=---='
//
//           .............................................
//                     佛祖保佑             永无BUG
//            佛曰:
//                     写字楼里写字间,写字间里程序员;
//                     程序人员写程序,又拿程序换酒钱。
//                     酒醒只在网上坐,酒醉还来网下眠;
//                     酒醉酒醒日复日,网上网下年复年。
//                     但愿老死电脑间,不愿鞠躬老板前;
//                     奔驰宝马贵者趣,公交自行程序员。
//                     别人笑我忒疯癫,我笑自己命太贱;
//                     不见满街漂亮妹,哪个归得程序员?
View Code

没有思路(不会证明:
纯写出来的话发现:
3 3 的列式结果是 1*C(3,1)+2*C(5,1)+3*C(10,1)可以化简为1*C(3,1)+2*C(4,2)+3*C(5,3) 即 i*C(i-n+1,i) 

 

标签:__,const,int,res,暑假,return,include,集训
来源: https://www.cnblogs.com/yeonnyuui/p/16559996.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有