栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3841 Cards

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3841 Cards

#include <iostream>#include <queue> #include <stack> #include <map> #include <set> #include <bitset> #include <cstdio> #include <algorithm> #include <cstring> #include <climits>#include <cstdlib>#include <cmath>#include <time.h>#define maxn 50005#define maxm 4005#define eps 1e-7#define mod 1000000007#define INF 0x3f3f3f3f#define PI (acos(-1.0))#define lowbit(x) (x&(-x))#define mp make_pair#define ls o<<1#define rs o<<1 | 1#define pii pair<int, int>#pragma comment(linker, "/STACK:16777216")typedef long long LL;typedef unsigned long long ULL;using namespace std;LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}LL f[55];LL g[55];int hash[200];int c[55];char s[100];void init(){hash['A'] = 1;hash['2'] = 2;hash['3'] = 3;hash['4'] = 4;hash['5'] = 5;hash['6'] = 6;hash['7'] = 7;hash['8'] = 8;hash['9'] = 9;hash['J'] = 11;hash['Q'] = 12;hash['K'] = 13;f[0] = 1;for(int i = 1; i <= 50; i++) f[i] = f[i-1] * i % mod;g[50] = powmod(f[50], mod-2);for(int i = 49; i >= 0; i--) g[i] = g[i+1] * (i + 1) % mod;}void work(){memset(c, 0, sizeof c);int len = strlen(s), cnt = 0;for(int i = 0; i < len; i++) {if(s[i] == '1') c[10]++, i++;else c[hash[s[i]]]++;cnt++;}int dep = 52 - cnt;if(dep == 0 || dep == 52) {printf("0n");return;}for(int i = 1; i <= 13; i++) c[i] = 4 - c[i];LL ans = 0;for(int k = 0; k < len; k++) {int t;if(s[k] == '1') t = 10, k++;else t = hash[s[k]];if(dep == 0) break;for(int i = 1; i < t; i++) {if(c[i]) {c[i]--;LL tt = 1;int tot = dep-1;for(int j = 1; j <= 13; j++)if(c[j]) {tt = tt * f[tot] % mod * g[c[j]] % mod * g[tot - c[j]] % mod;tot -= c[j];}ans = (ans + tt) % mod;c[i]++;}}if(c[t]) c[t]--;else break;dep--, cnt--;}if(dep == 0 && cnt) ans++;printf("%lldn", ans % mod);}int main(){init();while(scanf("%s", s)!=EOF) {work();}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/367083.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号