题意:给你52张牌,已知一个牌的序列,然后利用剩余的牌,能排成多少个序列,这个序列比已知的序列字典序小。

思路:从左到右尽可能放比已知序列相应位置小,找不到就放一样,然后求组合数就可以。多重集排列定理:令s时一个多重集,有k个不同类型的元素,各元素的重数分别为n1,n2......nk,令s的大小为n=n1+n2+......nk,则s的排列数为    n!/(n1!*n2!.....nk!);

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#define ll long long
#define maxn 100010
using namespace std;
const int mod=; char str[maxn];
int num[maxn];
ll f[maxn];
map<char,int>q; void inti()
{
f[]=;
for(int i=; i<=; i++)
f[i]=(f[i-]*i)%mod;
q['A']=;
for(int i=; i<=; i++)
q[''+i]=i;
q['']=;
q['J']=;
q['Q']=;
q['K']=;
} ll mult_mod(ll a,ll b,ll c)
{
a%=c;
b%=c;
ll ret=;
ll tmp=a;
while(b)
{
if(b&)
{
ret+=tmp;
if(ret>c) ret-=c;
}
tmp<<=;
if(tmp>c) tmp-=c;
b>>=;
}
return ret;
} ll pow_mod(ll a,ll n)
{
ll ret=;
ll temp=a%mod;
while(n)
{
if(n&)
{
ret=(ret*temp)%mod;
}
temp=(temp*temp)%mod;
n>>=;
}
return ret;
}
int main()
{
inti();
while(scanf("%s",str)!=EOF)
{
int k=strlen(str);
for(int i=; i<=; i++)
{
num[i]=;
}
int cnt=;
for(int i=; i<k; i++)
{
num[q[str[i]]]--;
cnt--;
if(str[i]=='') i++;
}
ll ans=;
int m=cnt;
bool flag=false;
for(int i=; i<k; i++)
{
if(cnt==) break;
for(int j=; j<=; j++)
{
if(num[j]>&&j<q[str[i]])
{
ll x=f[cnt-];
ll y=;
for(int c=; c<=; c++)
{
if(c==j)
{
y=(y*f[num[c]-])%mod;
continue;
}
y=(y*f[num[c]])%mod;
}
x=(x*pow_mod(y,mod-))%mod;
ans=(ans+x)%mod;
}
}
if(num[q[str[i]]]==)
{
flag=true;
break;
}
num[q[str[i]]]--;
cnt--;
if(str[i]=='') i++;
}
if(!flag&&m<-m)
ans=(ans+)%mod;
printf("%lld\n",ans);
}
return ;
}

zoj 3841 Cards的更多相关文章

  1. POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径)

    POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / ...

  2. zoj 2734 Exchange Cards【dfs+剪枝】

    Exchange Cards Time Limit: 2 Seconds      Memory Limit: 65536 KB As a basketball fan, Mike is also f ...

  3. POJ 1511 Invitation Cards (ZOJ 2008) 使用优先队列的dijkstra

    传送门: http://poj.org/problem?id=1511 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1008 ...

  4. 【ZOJ】3380 Patchouli's Spell Cards

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3957 题意:m个位置,每个位置填1~n的数,求至少有L个位置的数一样的概率(1 ...

  5. zoj 3380 Patchouli's Spell Cards 概率DP

    题意:1-n个位置中,每个位置填一个数,问至少有l个数是相同的概率. 可以转化求最多有l-1个数是相同的. dp[i][j]表示前i个位置填充j个位置的方案数,并且要满足上面的条件. 则: dp[i] ...

  6. ZOJ 2852 Deck of Cards DP

    题意: 一一个21点游戏. 1. 有三个牌堆,分别为1X,2X,3X. 2. 纸牌A的值为1,纸牌2-9的值与牌面面相同,10(T).J.Q.K的值为10,而而joke(F)的值为 任意大大. 3. ...

  7. Deck of Cards ZOJ - 2852 dp 多决策 三维 滚动更新

    题意:一个特殊21点游戏 具体http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2852 题解:建一个三维dp,表示三个卡槽分别 ...

  8. ZOJ 3380 Patchouli's Spell Cards

    方案数,$dp$. 总的方案数有$n^m$种,符合要求的直接算不好算,可以算反面,即不符合要求的. 设$dp[i][j]$表示前$i$种等级填了$j$个位置,那么$dp[i][j]=sum(dp[i- ...

  9. 重拾ZOJ 一周解题

    ZOJ 2734 Exchange Cards 题目大意: 给定一个值N,以及一堆卡片,每种卡片有一个值value和数量number.求使用任意张卡片组成N的方式. 例如N = 10 ,cards(1 ...

随机推荐

  1. one problem about Apple Keychain in use

    解决方案 Add Security.framework, then rebuild. Sometimes I find I have to build clean and then rebuild. ...

  2. 基于 CoreText 实现的高性能 UITableView

    引起UITableView卡顿比较常见的原因有cell的层级过多.cell中有触发离屏渲染的代码(譬如:cornerRadius.maskToBounds 同时使用).像素是否对齐.是否使用UITab ...

  3. spring计划任务,springMvc计划任务,Spring@Scheduled,spring定时任务

    spring计划任务,springMvc计划任务,Spring@Scheduled,spring定时任务 >>>>>>>>>>>> ...

  4. C# addin 开发心得记录

    1.环境 2012 新建项目-2010外接程序 2.新建项-功能区  创建菜单等 发布: 1.InstallShield  2015 2.打包 说明按地址-https://msdn.microsoft ...

  5. php错误处理和异常处理

    PHP错误处理有两种:标准的错误处理和异常(OOP语法新出现的错误处理机制)

  6. order by跟group by 跟having----------------sum() 求和   avg()求平均   count() 求个数--------------like

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoEAAACdCAIAAABEujUmAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWX ...

  7. Java-struts2 之中文乱码问题

    中文乱码问题,是个很麻烦的问题,有时候你发现,你表单页面的编码是UTF-8 Stutrst.xml也有这么一句话 <constant name="struts.i18n.encodin ...

  8. query 防止ajax重复提交

    项目用到js了,首选jquery,能用库用库,原则. 碰到重复提交的问题,禁止住才行.百度google,还是Google给力. 知乎上有个高人,总结了四种,利用Jquery .post方法返回jqXH ...

  9. ios动力特效,最重要的一点 属性保持(写了动力特效但是没效果的原因就在这里)

    @property (nonatomic, strong) UIDynamicItemBehavior *square1PropertiesBehavior; @property (nonatomic ...

  10. C# DataTable的詳細用法 - hcw_peter的专栏 - 博客频道 - CSDN

    C# DataTable的詳細用法 - hcw_peter的专栏 - 博客频道 - CSDN.NET 在项目中经常用到DataTable,如果DataTable使用得当,不仅能使程序简洁实用,而且能够 ...