2 条题解
-
0
https://www.luogu.com.cn/problem/solution/P4345
#include<bits/stdc++.h> // by: hansang using namespace std; typedef long long LL; const LL P=2333; const int N=2333+10; LL f[N][N], c[N][N]; LL Lucas(LL n, LL m) { if((m==0) || (n==m)) return 1; else if(n<m) return 0; else return c[n%P][m%P]*Lucas(n/P, m/P)%P; } LL F(LL n, LL m) { if(m<0) return 0; else if(n==0 || m==0) return 1; else if(n<P && m<P) return f[n][m]; else return (f[n%P][P-1]*F(n/P, m/P-1)+f[n%P][m%P]*Lucas(n/P, m/P))%P; } int main() { int T; scanf("%d", &T); memset(c, 0, sizeof(c)); memset(f, 0, sizeof(f)); for(int i=0; i<=N-10; i++) c[i][i]=c[i][0]=1, f[i][0]=1; for(int i=1; i<=N-10; i++) for(int j=1; j<=N-10; j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%P; for(int i=0; i<=N-10; i++) for(int j=1; j<=N-10; j++) f[i][j]=(f[i][j-1]+c[i][j])%P; while(T--) { LL n, m; scanf("%lld%lld", &n, &m); printf("%lld\n", F(n, m)); } return 0; } -
0
https://www.luogu.com.cn/problem/solution/P4345
#include<bits/stdc++.h> // by: hansang using namespace std; typedef long long LL; const LL P=2333; const int N=2333+10; LL f[N][N], c[N][N]; LL Lucas(LL n, LL m) { if((m==0) || (n==m)) return 1; else if(n<m) return 0; else return c[n%P][m%P]*Lucas(n/P, m/P)%P; } LL F(LL n, LL m) { if(m<0) return 0; else if(n==0 || m==0) return 1; else if(n<P && m<P) return f[n][m]; else return (f[n%P][P-1]*F(n/P, m/P-1)+f[n%P][m%P]*Lucas(n/P, m/P))%P; } int main() { int T; scanf("%d", &T); memset(c, 0, sizeof(c)); memset(f, 0, sizeof(f)); for(int i=0; i<=N-10; i++) c[i][i]=c[i][0]=1, f[i][0]=1; for(int i=1; i<=N-10; i++) for(int j=1; j<=N-10; j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%P; for(int i=0; i<=N-10; i++) for(int j=1; j<=N-10; j++) f[i][j]=(f[i][j-1]+c[i][j])%P; while(T--) { LL n, m; scanf("%lld%lld", &n, &m); printf("%lld\n", F(n, m)); } return 0; }</p>
- 1
信息
- ID
- 6256
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 4
- 已通过
- 3
- 上传者