【JZOJ 4924】 向再见说再见

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/lyd_7_29/article/details/53789678

Description


Analysis

考虑DP
首先把两队的人从小到大排好序
设f[i][j]表示做到第i个人,其中A队有j个人赢的方案数。
但是,由于转移涉及与i后面的人匹配,在保证正确的情况下,时间会爆
似乎不可做了
本蒟蒻到这里就不会了,下面的方法着实巧妙
f的转移不考虑输的方案数,就考虑赢的方案数。
f[i][j]=f[i1][j]+f[i1][j1](pos[i](j1))
第i个人,我可以不理它,也可以让他赢,因此转移如上
pos[i]表示A[i]能赢多少个B中的人
那么,设g[i]=f[n][i](ni)!,其意义为A队中n个人有i个人赢,其他人随意匹配的方案数,也即至少有i个人赢的方案数
这一步非常巧妙,应反复斟酌
h[i]表示为我们要求的答案,根据实际意义
g[i]=jih[j]Cij
那么
h[i]=g[i]j>ih[j]Cij
所以我们倒推一遍就能算出答案了
但是为什么有一个系数Cij
因为g[i]=f[n][i](ni)!,这也就意味着会有多个状态一乘阶乘之后变成一样的状态了,那么要算上重复的,这些重复状态个数显然就是C

Code

#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
typedef long long ll;
const int N=2010;
const ll mo=1e9+7;
int n,m,a[N],b[N],c[N];
ll f[N][N],g[N],h[N],fac[N],C[N][N];
int main()
{
    scanf("%d %d",&n,&m);
    if((n+m)%2)
    {
        printf("0");
        return 0;
    }
    fac[0]=1;
    fo(i,1,n) fac[i]=fac[i-1]*i%mo;
    fo(i,0,n)
        fo(j,0,i)
            if(j==0 || j==n) C[i][j]=1;
            else C[i][j]=(C[i-1][j]+C[i-1][j-1])%mo;
    fo(i,1,n) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    fo(i,1,n) scanf("%d",&b[i]);
    sort(b+1,b+n+1);
    int j=0;
    fo(i,1,n)
    {
        while(a[i]>b[j+1] && j<n) j++;
        c[i]=j;
    }
    f[0][0]=1;
    fo(i,1,n)
        fo(j,0,i)
            f[i][j]=(f[i-1][j]+f[i-1][j-1]*(c[i]-j+1)%mo)%mo;
    fo(i,0,n) g[i]=f[n][i]*fac[n-i]%mo;
    fd(i,n,0)
    {
        h[i]=g[i];
        fo(j,i+1,n) h[i]=(h[i]-h[j]*C[j][i]%mo+mo)%mo;
    }
    ll ans=h[(n+m)/2];
    if(m) ans=(ans+h[(n-m)/2])%mo;
    printf("%lld",ans);
    return 0;
}
展开阅读全文

再见,为明天……………………………………………………………………………………

06-26

[size=14px][color=#0000FF]暖暖的感动rn深深的惭愧rn最对不起的人,其实是自己rnrn总找不到出口rn也许rn真是为辅新词强说愁rn于是习惯了愁rnrn或许还是不知道自己想要的rn或许心太贪rn或许想要的太多……rn亦或许想要的总做不到rn于是破罐子破摔……rnrn明天谁知道会怎样呢?rn但今天的努力是必须的rn心是自己的rn选择是自己的rn快乐是自己的rn幸福是需要付出努力的……rnrnPS:混水源的日子,有快乐,更多是颓废。最大的收获,是在这里认识了不少的朋友。见过的没见过的,给过我暖暖的感动。也是第一次觉得网络是如此的贴近。rn可是明白自己需要去做更多的事情,我不能再由着自己随心所欲。人战胜自己很难,但是当还未曾和自己对决就放弃,只能一辈子浑浑噩噩过了。其实心里明白,我还是有理想,我还是不甘平庸,所以才会有那么多的矛盾。rn总是喜欢往回看,而不曾努力往前走。过去的真的只能过去了,犯的错误也罢,留有多大的遗憾我们都无法改变。记住昨天的教训为明天努力才是最好的收获,不是吗?rn今天打开那个很久不曾上线的QQ,大学同学给我发了信息,然后有陌生人加我为好友。有点无奈,24岁不知道算不算剩女,其实我一直都有自己的坚持,爱情是“宁愿缺着也不将就”的期待,可别人眼里成了我要求高、挑剔!于是我的那些男闺蜜女闺蜜都想方设法给我制造机会去认识他们认为合适的人。真难为大家一片好意。很多人都为我操心着,操心我的阴晴不定的情绪,操心我的终身大事。可我却看不到自己的努力!也许叔叔说的是对的“所谓纵心容易,收心难,我的问题的根本不是不知道该去怎么做?而是真心愿不愿意去做”,真的是太过于纵容了吧,自己纵容自己,别人也纵容我。我突然想,凭什么我上班坐那里说自己情绪不好,然后别人默默帮我把活干了。 自己还整天抱怨。我真以为自己是谁了,人家实习生都做的比我好。希望明天去办公室,不管怎样,把自己该做的事情做好!!!我没有理由享受人家的照顾!rn记得“美女她妈”说了,如果内心足够强大,就不用在这里大声咋呼,我想我的内心总是不够强大,发这个帖子,只是想在自己还是忍不住来这里无所事事的时候,给自己一个鞭策![/color][/size] 论坛

谢谢Netbeans向Eclipse再见!!!

05-11

What to use for huge applications? NetBeans or Eclipsern(一美国Eclipse用户心生)rnrnOf late I have been working on a telecom billing application. Not to say... its a huge application with many packages and 100s of java files in each one of them. I used to develop on a machine with 512 MB of RAM using Eclipse Platform. But the trouble I was facing with Eclipse was it being very very slow in response to the user actions. For eg.. I had to wait a couple of seconds and sometimes even minutes on pressing a 'dot' after an object name to open the method helper menu. It was becoming more and more frustrating for me day by day. Many a times to avoid this frustration I also used to work on EditPlus, which i think was the fastest editor but with no context help etc.rnrnThen one fine day I came across NetBeans 5.0. I thought to give it a try. The migration from Eclipse to NetBeans 5.0 was very easy. With their Eclipse Project Importer plugin it was bread and butter for me. And huuu developing my project in NetBeans 5.0 is much faster than the Eclipse. With the support of Tomcat and Sun Application Server built into the IDE itself the deployment and execution of my application is done on a fly. I never use EditPlus Now.rnrnThanks to NetBeans & Goodbye to Eclipse.rnrnFor me NetBeans has resolved many problems. What do you feel. Have you given a try to NetBeans for sometime or do you think that Eclipse is just fine.rnrnYour opinion can help millions of java developers worldwide. 论坛

没有更多推荐了,返回首页