越狱
盒子与球
斯特林第二类数(用dp求)*盒子的阶乘
int dp[11][11]; //n>=k
int A(int x){
int res=1;
fer(i,2,x+1)res*=i;
return res;
}
signed main(){
IOS;
dp[2][1]=dp[2][2]=dp[1][1]=1;
fer(i,3,11){
dp[i][1]=1;
fer(j,2,i){
dp[i][j]=j*dp[i-1][j]+dp[i-1][j-1];
}
dp[i][i]=1;
}
int n,r;cin>>n>>r;
cout<<dp[n][r]*A(r);
return 0;
}
矩阵乘法
const int N=1e3+1,mod=1e9+7;
int a[N][N],b[N][N],res[N][N];
signed main(){
IOS;
int l,m,n; cin>>l>>m>>n;
fer(i,0,l){
fer(j,0,m)cin>>a[i][j];
}
fer(i,0,m){
fer(j,0,n){
cin>>b[i][j];
}
}
//result l*n
fer(i,0,l){
fer(j,0,n){
fer(k,0,m){
res[i][j]+=a[i][k]*b[k][j];
}
}
}
fer(i,0,l){
fer(j,0,n){
cout<<res[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
找朋友
最小的:1、1、1、1、……、n-m+1
最大的:n/m平均分,n%m平均分到每个小组里
res=
C
x
2
C_x^2
Cx2
int C(int x,int k){
int res=1;
for(int i=x;i>x-k;i--){
res*=i;
}
fer(i,2,k+1)res/=i;
return res;
}
signed main(){
IOS;
int n,m;cin>>n>>m;
int res1=0,res2=0;
int x=n/m;
int y=n%m;
//y个 C_{x+1}^2,(m-y)个C_x^2
res1=y*C(x+1,2)+(m-y)*C(x,2);
res2=C(n-m+1,2);
cout<<res1<<" "<<res2;
return 0;
}
点餐
signed main(){
IOS;
int a;cin>>a;
int b[3];
fer(i,0,3)cin>>b[i];
if(b[0]+b[1]+b[2]<=2*a)cout<<"YES";
else cout<<"NO";
return 0;
}