zoj 3841 Cards
题意:给你52张牌,已知一个牌的序列,然后利用剩余的牌,能排成多少个序列,这个序列比已知的序列字典序小。
思路:从左到右尽可能放比已知序列相应位置小,找不到就放一样,然后求组合数就可以。多重集排列定理:令s时一个多重集,有k个不同类型的元素,各元素的重数分别为n1,n2......nk,令s的大小为n=n1+n2+......nk,则s的排列数为 n!/(n1!*n2!.....nk!);
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <map> 5 #define ll long long 6 #define maxn 100010 7 using namespace std; 8 const int mod=1000000007; 9 10 char str[maxn]; 11 int num[maxn]; 12 ll f[maxn]; 13 map<char,int>q; 14 15 void inti() 16 { 17 f[0]=1; 18 for(int i=1; i<=50; i++) 19 f[i]=(f[i-1]*i)%mod; 20 q['A']=1; 21 for(int i=2; i<=9; i++) 22 q['0'+i]=i; 23 q['1']=10; 24 q['J']=11; 25 q['Q']=12; 26 q['K']=13; 27 } 28 29 ll mult_mod(ll a,ll b,ll c) 30 { 31 a%=c; 32 b%=c; 33 ll ret=0; 34 ll tmp=a; 35 while(b) 36 { 37 if(b&1) 38 { 39 ret+=tmp; 40 if(ret>c) ret-=c; 41 } 42 tmp<<=1; 43 if(tmp>c) tmp-=c; 44 b>>=1; 45 } 46 return ret; 47 } 48 49 ll pow_mod(ll a,ll n) 50 { 51 ll ret=1; 52 ll temp=a%mod; 53 while(n) 54 { 55 if(n&1) 56 { 57 ret=(ret*temp)%mod; 58 } 59 temp=(temp*temp)%mod; 60 n>>=1; 61 } 62 return ret; 63 } 64 int main() 65 { 66 inti(); 67 while(scanf("%s",str)!=EOF) 68 { 69 int k=strlen(str); 70 for(int i=1; i<=13; i++) 71 { 72 num[i]=4; 73 } 74 int cnt=52; 75 for(int i=0; i<k; i++) 76 { 77 num[q[str[i]]]--; 78 cnt--; 79 if(str[i]=='1') i++; 80 } 81 ll ans=0; 82 int m=cnt; 83 bool flag=false; 84 for(int i=0; i<k; i++) 85 { 86 if(cnt==0) break; 87 for(int j=1; j<=13; j++) 88 { 89 if(num[j]>0&&j<q[str[i]]) 90 { 91 ll x=f[cnt-1]; 92 ll y=1; 93 for(int c=1; c<=13; c++) 94 { 95 if(c==j) 96 { 97 y=(y*f[num[c]-1])%mod; 98 continue; 99 } 100 y=(y*f[num[c]])%mod; 101 } 102 x=(x*pow_mod(y,mod-2))%mod; 103 ans=(ans+x)%mod; 104 } 105 } 106 if(num[q[str[i]]]==0) 107 { 108 flag=true; 109 break; 110 } 111 num[q[str[i]]]--; 112 cnt--; 113 if(str[i]=='1') i++; 114 } 115 if(!flag&&m<52-m) 116 ans=(ans+1)%mod; 117 printf("%lld\n",ans); 118 } 119 return 0; 120 }
View Code
转载于:https://www.cnblogs.com/fanminghui/p/4360205.html
zoj 3841 Cards相关推荐
- ZOJ 3380 Patchouli's Spell Cards(概率DP)
Patchouli's Spell Cards Time Limit: 7 Seconds Memory Limit: 65536 KB Patchouli Knowledge, the u ...
- ★ZOJ 3380 Patchouli's Spell Cards 详细题解 (递推+组合数求方案数)
Patchouli's Spell Cards Time Limit: 7 Seconds Memory Limit: 65536 KB Patchouli Knowledge, the u ...
- ZOJ 3380 Patchouli's Spell Cards [基础概率DP+大数]
Patchouli's Spell Cards Time Limit: 7 Seconds Memory Limit: 65536 KB Patchouli Knowledge, the u ...
- ZOJ 3380 Patchouli's Spell Cards [基础DP+大数]
Description Patchouli Knowledge, the unmoving great library, is a magician who has settled down in t ...
- 【ZOJ】3380 Patchouli's Spell Cards
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3957 题意:m个位置,每个位置填1~n的数,求至少有L个位置的数一样的概率(1 ...
- ZOJ 3380 Patchouli's Spell Cards(概率+大数)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3957 题意:m个位置,每个位置可以放n种数字(1-n).问至少有L个 ...
- ZOJ 3380 Patchouli's Spell Cards( 概率DP)
题意:用n个数填充m个位置,问有大于等于l个相同数字的概率. 这个题看了很多题解,大部分代码都是有点问题的,一开始dp的状态都是一样的.(具体见下) 思路:设dp[i][j] 为用前i个数填充j个位置 ...
- 【概率DP】 ZOJ 3380 Patchouli's Spell Cards
通道 题意:有m个位置,每个位置填入一个数,数的范围是1~n,问至少有L个位置的数一样的概率 思路: 总数是n^m,我们求没有L个位置一样的数的概率* 设 dp[i][j]表示用前i个数,填充j个位置 ...
- ZOJ 3380 Patchouli's Spell Cards
方案数,$dp$. 总的方案数有$n^m$种,符合要求的直接算不好算,可以算反面,即不符合要求的. 设$dp[i][j]$表示前$i$种等级填了$j$个位置,那么$dp[i][j]=sum(dp[i- ...
最新文章
- 电脑安装pandas报错_python3.8下如何解决pandas报错No module named '_bz2'问题
- 人工智能热门技术研究课题
- putty 连接虚拟机_使用Putty连接虚拟机
- Android 多线程实现异步执行demo,线程池使用demo
- 【今日CV 视觉论文速览】05 Dec 2018
- java anonymous class_java declare anonymous class using proxy api
- 大白话5分钟带你走进人工智能-第二十二节决策树系列之概念介绍(1)
- mac 搭建mysql环境_Mac下MySQL环境搭建的步骤详解
- 自由空间模型损耗计算详细说明
- FileZilla Server多实例监听
- Excel如何安装VBA?
- 第十一期_MSF 后渗透《Metasploit Unleashed Simplified Chinese version(Metasploit官方文档教程中文版)》
- ORACLE表空间和表碎片分析及整理方法
- openresty ngx_lua日志操作
- oracle11g在linux7的静默安装脚本
- hfish蜜罐搭建及简单使用
- Stimulsoft Dashboards.JS JavaScript 2203.1.0仪表板
- 最厉害的面试技巧都有哪些?
- linux筑基之常用命令
- 彻底解决jdbc数据库连接超时重试-communication link failure的正确姿势
热门文章
- 一个机器学习博士的忠告
- 网站的服务器区域可以造假吗,如何伪造DNS服务器?
- python分析基金数据_python基金会(大数据分析),的,PYTHON,基础,选择,练习
- 翻转字符串里面的单词(*****)
- 为什么要学习C++,它到底能做什么?
- python装饰器副作用_对Python 装饰器的理解心得
- 2021-02-25
- php 降低图像大小,在PHP中调整图像大小
- 用 Linux 和 Apache Hadoop 进行云计算
- Nexus配置内部仓库