当前位置: 代码迷 >> 综合 >> BZOJ5445 [Ceoi2018]Toys
  详细解决方案

BZOJ5445 [Ceoi2018]Toys

热度:50   发布时间:2023-12-14 16:22:43.0

标签:数学

题目

题目传送门

题意简述:达达兔有很多不同种类玩具,每种玩具可能有很多个(存在区别),每天达达兔可以在不同种类的玩具中每种选择一个,组合起来,最多可以玩耍n天(n天中不存在重复组合的情况),问有多少种情况可以满足,求达达兔可以拥有多少玩具

分析

一眼就知道是数学题

然后根据样例简单推推

发现答案就是可以将n分解的不同组合

算是水题了吧qwq

code

#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #define rep(i,a,b) for(int i=a;i<=b;i++) #define dep(i,a,b) for(int i=a;i>=b;i--) #define ll long long #define mem(x,num) memset(x,num,sizeof x) #define reg(x) for(int i=last[x];i;i=e[i].next) using namespace std; inline ll read(){
     ll f=1,x=0;char ch=getchar();while(ch<'0'||ch>'9'){
     if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){
     x=x*10+ch-'0';ch=getchar();}return x*f; } //******head by yjjr****** const int maxn=1e7+6; int n,ans[maxn],top=0; void dfs(int n,int l,int s){
     ans[++top]=s+n-1;int tmp=trunc(sqrt(n));rep(i,l,tmp)if(n%i==0)dfs(n/i,i,s+i-1); } int main(){
     n=read();dfs(n,2,0);sort(ans+1,ans+1+top);int e=unique(ans+1,ans+1+top)-ans-1;printf("%d\n",e);rep(i,1,e)printf("%d ",ans[i]);return 0; }