剩下的不太会就没接着打了,没有注意到比赛截至时间,好像提前了几分钟公开题解。意识到的时候已经来不及了。。。抱歉。。。
——————————————————————————————————————
A.走格子
按题意模拟即可
#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define mem(W) memset(W,0,sizeof(W))
#define rep(i,a,b) for(int i=a;i<=b;++i)
inline int read() {char c=getchar();int x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return x*f;
}
typedef long long ll;
const int N = 1000 + 100;
using namespace std;
int n,a[N][N],m;
int dx[]={1,0,-1,0};
int dy[]={0,-1,0,1};
int ck(int x,int y){if(x<=0||x>n||y<=0||y>n)return 0;if(a[x][y])return 0;return 1;
}
int main() {scanf("%d%d",&n,&m);int ax=1,ay=1,f=0,stp=0,flag=0;a[ax][ay]=1;while(1) {while(ck(ax+dx[f%4],ay+dy[f%4])){ax+=dx[f%4],ay+=dy[f%4],++stp,a[ax][ay]=1;if(stp==m) {flag=1;break;}}if(flag)break;++f;}printf("%d %d\n",ax,ay);return 0;
}
B.求值2
组合数第n层的平方和=C(2*n,n),枚举求和即可
#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define mem(W) memset(W,0,sizeof(W))
#define rep(i,a,b) for(int i=a;i<=b;++i)
inline int read() {char c=getchar();int x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return x*f;
}
typedef long long ll;
const int N = 2000000 + 100;
const ll mod = 998244353;
using namespace std;
int n;
ll ans=0;
ll fc[N],inv[N];
ll q_pow(ll a,ll b) {ll ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1LL;}return ans;
}
ll C(ll n, ll m) {return (fc[n]*inv[m])%mod*inv[n-m]%mod;
}
int main() {n=read();fc[0]=1; rep(i,1,2*n)fc[i]=(fc[i-1]*i)%mod;inv[2*n]=q_pow(fc[2*n],mod-2);for(int i=2*n-1;i>=0;--i)inv[i]=(inv[i+1]*(i+1LL))%mod;ans=0;for(int i=1;i<=n;++i){ans=(ans+C(i<<1,i))%mod;}cout << ans << endl;return 0;
}
C.简单环
dp[s][i]表示,以s最低位为起点,i为终点的简单路数目,转移dp[s|(1<<j)][j]+=dp[s][i]当i,j有边且j点未经过,转移的时候如果有以j点为起点,且i和j有边相连,就加到答案里。点数小于等于2不要计入答案。原题:codeforces 11D
#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define mem(W) memset(W,0,sizeof(W))
#define rep(i,a,b) for(int i=a;i<=b;++i)
inline int read() {char c=getchar();int x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return x*f;
}
typedef long long ll;
const int N = 21;
const ll mod = 998244353;
using namespace std;
ll q_pow(ll a,ll b) {ll ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1LL;}return ans;
}
int n,m,k,g[N][N],t,u,v;
ll dp[(1<<N)][N],ans[N],inv2;
int ct(int s){int ans=0;for(int i=s;i;i-=(i&(-i)))++ans;return ans;
}
int main() {inv2=q_pow(2LL,mod-2);n=read(),m=read(),k=read();rep(i,1,m)u=read(),v=read(),g[u-1][v-1]=g[v-1][u-1]=1;rep(i,0,n-1)dp[1<<i][i]=1;rep(s,1,(1<<n)){rep(i,0,n-1){if(!(s&(1<<i))||!dp[s][i])continue;for(t=0;!(s&(1<<t));++t);rep(j,t,n-1)if(g[i][j]){if(!(s&(1<<j)))dp[s|(1<<j)][j]+=dp[s][i];if((s&(1<<j))&&j==t&&ct(s)>2)ans[ct(s)%k]=(ans[ct(s)%k]+dp[s][i])%mod;}}}rep(i,0,k-1)printf("%lld\n",(ans[i]*inv2)%mod);return 0;
}