Codeforces Global Round 7 C. Permutation Partitions(思维)

Sara/Sarah ·
更新时间:2024-09-20
· 945 次阅读

传送门 题意:

给两个数n,k
把长度为n的数组分成k个不相交的区间
把分成每个区间的最大值加在一起
找到和的最大值,并输出共有多少种分法等于该最大值

思路:

要想值最大,那前k大的数肯定在不同的区间
分法的话,就看这k个区间,每两个相邻的区间有几个数,该区间与下一个区间就有几种情况,把所有的乘起来即可

代码: #include #include #include #include #include #include #include #include #include #include #define pb push_back #define lb lower_bound #define ub upper_bound #define debug(x) cout<<x<<endl #define rep(i,a,b) for(int i=a;i=b;i--) typedef long long ll; using namespace std; const int MAXN=2e5+50; const int inf=0x3f3f3f3f; const int M=5000*4; const int mod=998244353; ll a[MAXN]; ll b[MAXN]; int main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); ll n,k; cin>>n>>k; rep(i,1,n){ cin>>a[i]; } if(n==k){ ll ans=n*(n+1)/2; cout<<ans<<" "<<1<<endl; return 0; } if(k==1){ cout<<n<<" "<<1<<endl; return 0; } ll ans=n*(n+1)/2-(n-k)*(n-k+1)/2; int p=n-k+1;//找前k大的数 int cnt=0; for(int i=1;i=p)b[++cnt]=i; } // cout<<cnt<<endl; ll lp=1; for(int i=2;i<=cnt;i++){ ll op=(b[i]-b[i-1]); lp=(lp*op)%mod; } cout<<ans<<" "<<lp<<endl; return 0; } /* 5 abbaxyzyx */
作者:_Alexander



permutation CodeForces global round

需要 登录 后方可回复, 如果你还没有账号请 注册新账号