题解 CF571A 【Lengthening Sticks】
我们先求出来所有可能的方案,共有
不合法的方案数要分三类讨论,
代码:
#include<bits/stdc++.h>
#define int long long
#define max(a,b) a>b?a:b
using namespace std;
int ans;
int C(int a,int b){
if(a<b)return 0;
if(b==2){
return a*(a-1)/2;
}
else{
return a*(a-1)*(a-2)/6;
}
}
void work(int a,int b,int c,int l){
for(int i=max(0,a+b-c);i<=l;i++){
int tmp=min(l-i,c+i-a-b);
ans-=C(tmp+2,2);
}
}
main(){
int a,b,c,l;
cin>>a>>b>>c>>l;
ans+=C(l+3,3);
work(a,b,c,l);
work(a,c,b,l);
work(b,c,a,l);
cout<<ans<<endl;
}