cf 1301c Ayoub's function

 题目大意:长度为n的序列,有m个1,问最多可以有多少子序列至少包含1个1。  

 

很明显,我们要平均分配0这样肯定是最优的。 

 1 #include<bits/stdc++.h>
 2 using namespace std;  
 3 #define ll long long 
 4 int const  N=1e5+10;  
 5 int t,n,m;  
 6 ll comb(ll x){
 7     return x*(x-1)/2;  
 8 }
 9 int main(){
10     scanf("%d",&t);  
11     while (t--){
12         scanf("%d%d",&n,&m);  
13         ll ans=comb(n+1);  
14         int t=min(n-m,m+1);  
15         if(t==0) {
16             printf("%lld\n",ans);  
17             continue;  
18         }
19         int d=(n-m)%t;  
20         int s=(n-m)/t;  
21         ll left=d*comb(s+2)+(t-d)*comb(s+1);  
22         printf("%lld\n",ans-left); 
23     }
24     return 0; 
25 }
View Code

 

posted @ 2020-03-15 17:33  zjxxcn  阅读(104)  评论(0编辑  收藏  举报