首页 > 其他分享 >Devu and Flowers CF451E

Devu and Flowers CF451E

时间:2023-04-21 16:56:43浏览次数:37  
标签:CF451E Flowers 花瓶 int cnt Devu ans include

Devu 有 n 个花瓶,第 ii 个花瓶里有 fi 朵花。他现在要选择 s 朵花。

你需要求出有多少种方案。两种方案不同当且仅当两种方案中至少有一个花瓶选择花的数量不同

 

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int M = 1<<20 ,mod=1e9+7;
#define int long long
#define ll long long
 int a[25],f[M];
 int fac[22];
 
 int k;
ll r,n[25],inv[25];

ll pow(ll a,ll b,ll p){
    ll ans=1;
    while(b){
        if (b%2) ans=(ans*a)%p;
        b/=2;
        a=(a*a)%p;
    }
    return ans;
}

void get_inv(ll n,ll p){
    inv[1]=1;
    for (ll i=2;i<=n;i++){
        inv[i]=inv[p%i]*(p-p/i)%p;
    }
}

int C(ll y,ll x){
    if (y<0||x<0||y<x) return 0;
    y%=mod;
    if (y==0 || x==0) return 1;
    ll ans=1;
    for (int i=0;i<x;i++){
        ans=1ll*ans*(y-i)%mod;
    }
    for (int i=1;i<=x;i++){
        ans=1ll*ans*inv[i]%mod;
    }
    return ans;
}
 
 signed main() {
 	int n,m;
 	get_inv(20,mod);
 	cin>>m>>n;
 	fac[0]=1;for(int i=1;i<20;i++) fac[i]=fac[i-1]*i ; 
 	
 	for(int i=1;i<=m;i++) cin>>a[i];
     int ans=C(m+n-1,m-1);
     
     for(int j=1;j<(1<<m);j++){
     	int t=m+n, cnt=0;
     	
     	for(int i=0;i<m;i++){
     		if((j>>i)&1) cnt++, t-=a[i+1];//
     	}
     	t-=cnt+1;
     	if(cnt&1) ans=(ans-C(t,m-1))%mod ;
     	else ans=ans+C(t,m-1)%mod ;
     }
     cout<<(ans+mod)%mod;
 }

 

标签:CF451E,Flowers,花瓶,int,cnt,Devu,ans,include
From: https://www.cnblogs.com/towboa/p/17341001.html

相关文章

  • Graduation-Project,Willow-Flowers-and-Love-Letter
    毕设、柳花和情书Datetime:2023-04-04T17:56+08:00Categories:FragmentTags:Diary发现自己没法记住纯音乐,有歌词的歌比较容易记忆,音节会构成旋律,但是纯音乐不一样,听了就忘,有点为此沮丧。但是有两首可以记得的,一首是永远同在,一首是犬夜叉的穿越时空的思念,因为亲自在EOP......
  • C - Choosing flowers(贪心)
    题目https://codeforces.com/contest/1379/problem/C题意输入t(≤1e4)表示t组数据。所有数据的m之和≤1e5。每组数据输入n(≤1e9)m(≤1e5)表示有m种......
  • POJ 3262 Protecting the Flowers 贪心
    题目描述FarmerJohnwenttocutsomewoodandleftN(2≤N≤100,000)cowseatingthegrass,asusual.Whenhereturned,hefoundtohishorrorthattheclus......
  • CodeForces 1423G Growing flowers
    洛谷传送门CF传送门先离散化颜色。考虑对每种颜色单独求出答案。对于颜色\(x\),可以用总方案数\(n-k+1\)减去一个\(x\)都不包含的区间数量。对于这个,假设相邻两个颜......
  • Vue DevUI v1.4 版本发布:从体验、效率、质量三个方面做了全方位的优化
    2022年9月1日,我们正式宣布VueDevUI组件库发布v1.0版本。VueDevUI1.0正式发布......
  • CF451E Devu and Flowers
    \(CF451E\)\(Devu\)\(and\)\(Flowers\)链接:https://www.luogu.com.cn/problem/CF451E题目描述:将一些球丢进一个盒子里,每一个求有一种颜色,有多少种本质不同的方法......
  • CF451E Devu and Flowers
    $CF451E$$Devu$$and$$Flowers$链接:https://www.luogu.com.cn/problem/CF451E题目描述:将一些球丢进一个盒子里,每一个求有一种颜色,有多少种本质不同的方法题解:......
  • React DevUI 18.0 正式发布
    Jay是一位经验丰富并且对质量要求很高的开发者,对Angular、React等多种框架都很熟悉,我们在开源社区认识,在我做开源社区运营的过程中,Jay给了我很多帮助,他也是ReactDevU......
  • 基于ResNet的花卉图片分类 —— tensorflow版(flowers image classification based on
    最近看了《TensorFlow深度学习实战(微课视频版)》——清华大学出版社一书中的11章节《基于ResNet的花卉图片分类》,觉得写的不错,是个关于ResNet的好例子,所以整理下,分享给......
  • DevUI开源经验分享:从0到1开始运营你的开源项目
    摘要:DevUI是面向企业中后台产品的开源前端解决方案,于2019年6月正式在GitHub开源,从当时的无人问津到去年8月累计1000Star,再到现如今上千名社区成员、上百位贡献者、达成了3......