agc005d

题目
思路:
考虑容斥,答案为\(\sum{(-1)^i*f_{i}}\)
对于f_{i},实际就是求用强制i个不合法,剩下的随便选。
由于长度固定,所以mod k不同的点互相独立
这样可以设f_{i,0/1}表示考虑到第i个点,选/不选i的方案数。
转移不必多说。
代码上可以将序列重排,让模数相同的放到一起。

启发:
对于差固定限制,不同模数间互相独立

#include<bits/stdc++.h>
using namespace std;
struct FIO{static const int BUF_SIZE=1<<19;char _i[BUF_SIZE],*_1=_i,*_2=_i,_o[BUF_SIZE],*_t=_o;inline char _gt(){if(_1==_2){_1=_i;_2=_i+fread(_i,1,BUF_SIZE,stdin);}return _1==_2?EOF:*_1++;}inline void _pt(char c){if(_t-_o==BUF_SIZE){fwrite(_o,1,BUF_SIZE,stdout);_t=_o;}*_t++=c;}int _pr=6,le,_ob[20];template<typename T>FIO&operator>>(T&x){x=0;char c=_gt();bool sg=false;while(c!=EOF&&(c<'0'||c>'9')){if(c=='-')sg=true;c=_gt();}while(c!=EOF&&c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=_gt();}if(sg)x=-x;return*this;}FIO&operator>>(char*s){char c=_gt();while(c!=EOF&&c<33)c=_gt();while(c!=EOF&&c>=33)*s++=c,c=_gt();*s='\0';return*this;}FIO&operator>>(string&s){s.clear();char c=_gt();while(c!=EOF&&c<33)c=_gt();while(c!=EOF&&c>=33)s+=c,c=_gt();return*this;}FIO&operator>>(char&x){char c=_gt();while(c!=EOF&&c<33)c=_gt();x=c;return*this;}FIO&operator>>(double&x){x=0;char c=_gt();bool sg=0;while(c!=EOF&&c<33)c=_gt();if(c=='-'){sg=1;c=_gt();}while(c!=EOF&&c>='0'&&c<='9'){x=x*10+(c^48);c=_gt();}if(c=='.'){c=_gt();double tp=0.1;while(c!=EOF&&c>='0'&&c<='9'){x+=(c^48)*tp;tp*=0.1;c=_gt();}}if(sg)x=-x;return*this;}FIO&setprecision(int n){_pr=n<0?0:n;return*this;}template<typename T>FIO&operator<<(T x){if(x<0){_pt('-');x=-x;}if(x==0){_pt('0');return*this;}char _b[20];int ps=0;while(x>0){_b[ps++]=(x%10)^48;x/=10;}while(ps>0)_pt(_b[--ps]);return*this;}FIO&operator<<(const char*s){while(*s)_pt(*s++);return*this;}FIO&operator<<(const string&s){for(char c:s)_pt(c);return*this;}FIO&operator<<(char c){_pt(c);return*this;}FIO&operator<<(double x){if(x<0)_pt('-'),x=-x;if(isnan(x))return _pt('n'),_pt('a'),_pt('n'),*this;if(isinf(x))return _pt('i'),_pt('n'),_pt('f'),*this;long long ip=(long long)x;x-=ip;if(_pr==0){x*=10;if(x>=5)ip++;return*this<<ip;}le=0;_ob[0]=0;for(int i=1;i<=_pr;i++){x*=10;_ob[++le]=(int)x;x-=(int)x;}x*=10;int _tp=(int)x;if(_tp>=5){int j=le;_ob[le]++;while(_ob[j]==10)_ob[j-1]++,_ob[j]=0,j--;}ip+=_ob[0];*this<<ip<<".";for(int i=1;i<=le;i++)*this<<_ob[i];return*this;}~FIO(){fwrite(_o,1,_t-_o,stdout);}}fst;
#define cin fst
#define cout fst
#define il inline
#define N 2005
#define mod 924844033
typedef long long ll;

int n,k,tot;
ll fac[N];

bool ty[N<<1];
ll dp[N<<1][N][2];

int main(){
	cin>>n>>k;
	fac[0]=1;
	for(int i=1;i<=n;i++)fac[i]=fac[i-1]*i%mod;
	for(int i=1;i<=k;i++){
		for(int t=0;t<=1;t++){
			ty[tot+1]=1;
			tot+=(n-i)/k+1;
		}
	}
	dp[0][0][0]=1;
	for(int i=1;i<=n*2;i++){
		for(int j=0;j<=n;j++){
			dp[i][j][0]=(dp[i-1][j][0]+dp[i-1][j][1])%mod;
			if(ty[i]==0&&j)dp[i][j][1]=dp[i-1][j-1][0];
		}
	}
	ll res=0;
	for(int i=0,f=1;i<=n;i++){
		res=(res+f*(dp[n*2][i][0]+dp[n*2][i][1])%mod*fac[n-i]%mod+mod)%mod;
		f=-f;
	}
	cout<<res;
	return 0;
}
posted @ 2026-09-11 21:11  whs_1007  阅读(4)  评论(0)    收藏  举报