Description

  Dragon loves lottery, he will try his luck every week. One day, the lottery company brings out a new form of lottery called accumulated lottery. In a normal lottery, you pick 7 numbers from N numbers. You will get reward according to how many numbers you match. If you match all 7 numbers, you will get the top prize for 1 billion dollars!!! Unlike normal lottery, an M-accumulated lottery allows you to pick M numbers from N numbers. If M is big enough, this may significantly increase your possibility to win. (Of course it cost more…)

  Some people buy multiple accumulated lotteries to guarantee a higher possibility to get the top prize. Despite of this, it’s still not worthy to guarantee a top prize.Knowing this, Dragon changes his target to second tier prize. To get a second tier prize, you need to contain all of the R numbers with M numbers picked.Given N, M and R, Dragon wants to know how many M-accumulated lotteries he needs to buy, so that he can guarantee that he can get at least the second tier prize.

 
  这个题目就是让我们找到至少需要几个彩票,能够覆盖每一个R。
  然后构造的话就是C(N,R)列,C(N,M)行。。。。。。
  不过对于8,5,4这个数据要15分钟才能出答案。。。。。。所以。。。。。。要打表。。。。。。(坑。。。。。。)
  现在还不明白为啥要这么慢。。。。。。
 
打表的代码如下:
#include<iostream>
#include<cstring> using namespace std; const int MaxN=;
const int MaxM=;
const int MaxNode=MaxN*MaxM;
const int INF=10e8; struct DLX
{
int U[MaxNode],D[MaxNode],L[MaxNode],R[MaxNode],col[MaxNode];
int H[MaxN],S[MaxM];
int ans;
int n,m,size; void init(int _n,int _m)
{
n=_n;
m=_m;
size=m;
ans=INF; for(int i=;i<=m;++i)
{
L[i]=i-;
R[i]=i+;
U[i]=D[i]=i; S[i]=;
}
L[]=m;
R[m]=; for(int i=;i<=n;++i)
H[i]=-;
} void Link(int r,int c)
{
col[++size]=c;
++S[c]; U[size]=U[c];
D[size]=c;
D[U[c]]=size;
U[c]=size; if(H[r]==-)
H[r]=L[size]=R[size]=size;
else
{
L[size]=L[H[r]];
R[size]=H[r];
R[L[H[r]]]=size;
L[H[r]]=size;
}
} void remove(int c)
{
for(int i=D[c];i!=c;i=D[i])
{
L[R[i]]=L[i];
R[L[i]]=R[i];
}
} void resume(int c)
{
for(int i=U[c];i!=c;i=U[i])
L[R[i]]=R[L[i]]=i;
} bool vis1[MaxM]; int getH()
{
int ret=; for(int i=R[];i!=;i=R[i])
vis1[i]=; for(int i=R[];i!=;i=R[i])
if(vis1[i])
{
++ret;
vis1[i]=; for(int j=D[i];j!=i;j=D[j])
for(int k=R[j];k!=j;k=R[k])
vis1[col[k]]=; //!!!!!!!!!!!!!!
} return ret;
} void Dance(int d)
{
if(getH()+d>=ans)
return; if(R[]==)
{
if(d<ans)
ans=d; return;
} int c=R[]; for(int i=R[];i!=;i=R[i])
if(S[i]<S[c])
c=i; for(int i=D[c];i!=c;i=D[i])
{
remove(i); for(int j=R[i];j!=i;j=R[j])
remove(j); Dance(d+); for(int j=L[i];j!=i;j=L[j])
resume(j); resume(i);
}
}
}; DLX dlx;
int N,M,R;
int C[][]; void getC()
{
for(int i=;i<=;++i)
C[i][]=; for(int i=;i<=;++i)
for(int j=;j<=i;++j)
C[i][j]=C[i-][j-]+C[i-][j];
} void numTOp(int *s,int x,int n,int m,int d)
{
if(m<=)
return; if(x>=C[n-][m-])
numTOp(s,x-C[n-][m-],n-,m,d+);
else
{
s[]=d;
numTOp(s+,x,n-,m-,d+);
}
} int pTOnum(int *s1,int *s2)
{
int vis[],ans1=; memset(vis,,sizeof(vis)); for(int i=;i<R;++i)
vis[s1[s2[i]-]]=; int tR=R-; for(int i=;i<=N && tR>=;++i)
{
if(vis[i]==)
ans1+=C[N-i][tR];
else
--tR;
} return ans1;
} void slove()
{
int s[];
int ts[],temp; dlx.init(C[N][M],C[N][R]); for(int i=;i<C[N][M];++i)
{
numTOp(s,i,N,M,); for(int j=;j<C[M][R];++j)
{
numTOp(ts,j,M,R,); temp=pTOnum(s,ts); dlx.Link(i+,temp+);
}
} dlx.Dance(); cout<<dlx.ans<<endl;
} int main()
{
ios::sync_with_stdio(false); int T; cin>>T; getC(); for(int cas=;cas<=T;++cas)
{
cin>>N>>M>>R; cout<<"Case #"<<cas<<": ";
slove();
} return ;
}

把结果保存到文件里然后再复制到一个数组就行了。。。。。。

(中等) HDU 4979 A simple math problem. , DLX+重复覆盖+打表。的更多相关文章

  1. hdu - 4979 - A simple math problem.(可反复覆盖DLX + 打表)

    题意:一种彩票共同拥有 N 个号码,每注包括 M 个号码,假设开出来的 M 个号码中与自己买的注有 R 个以上的同样号码,则中二等奖,问要保证中二等奖至少要买多少注(1<=R<=M< ...

  2. HDU 1757 A Simple Math Problem 【矩阵经典7 构造矩阵递推式】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1757 A Simple Math Problem Time Limit: 3000/1000 MS (J ...

  3. hdu 1757 A Simple Math Problem (乘法矩阵)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  4. HDU 1757 A Simple Math Problem (矩阵快速幂)

    题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...

  5. HDU 1757 A Simple Math Problem(矩阵)

    A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...

  6. HDU 1757 A Simple Math Problem (矩阵乘法)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  7. hdu 5974 A Simple Math Problem

    A Simple Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  8. hdu 1757 A Simple Math Problem(矩阵快速幂乘法)

    Problem Description Lele now is thinking about a simple function f(x). If x < f(x) = x. If x > ...

  9. HDU 1757 A Simple Math Problem(矩阵高速幂)

    题目地址:HDU 1757 最终会构造矩阵了.事实上也不难,仅仅怪自己笨..= =! f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + a9 ...

随机推荐

  1. 利用css的border实现画三角形思路原理

    1.利用Css 的border绘制三角形的原理: div的border是有宽度和颜色的,当div的宽度比较大的时候,比如上面代码每个边100像素,颜色又不一样,浏览器怎么渲染颜色呢?经测试发现,宽度较 ...

  2. 【转载】GDI 映像方式 之 SetViewportExtEx 与 SetWindowExtEx 解析

    所谓视口代表设备,比如屏幕. 窗口代表我们的思维. 我们对windows说在(5,6)处画个点(调用GDI函数).windows认为是在我们的思维的(5,6)处画了个点.(也就是说5,6是逻辑坐标,G ...

  3. 如何在使用eclipse的情况下,清理android项目中的冗余class文件和资源文件以及冗余图片

    在我们迭代项目的过程中,经常会启用某些功能,或者修改某些界面的问题,那么问题来了,这样很容易出现大量的冗余.java文件,冗余资源文件,一些冗余的界面文件等.那么问题既然出现了,那么如何去解决呢,这就 ...

  4. robot_framewok自动化测试

    robot_framewok自动化测试 http://wenku.baidu.com/view/691abcaa4b73f242336c5fec.html 接口自动化测试框架设计 http://wen ...

  5. Php和httpd.conf的配置

    http://www.cnblogs.com/homezzm/archive/2012/08/01/2618062.html http://book.51cto.com/art/201309/4096 ...

  6. HDU 5875 st+二分区间

    题目大意:给你n个数,q次询问,每次询问区间[l, r],问a[i]%a[i + 1] % a[i + 2]...%a[j](j <= r)的值 思路:st预处理维护,再二分区间,复杂度n*(l ...

  7. Android Camera Api的心得

    (一) 前言最近看Camera的api,觉得写的真的不错.现在翻译过来,给大家分享分享,译文可能不太好,大家将就着看哈. (二) 正文1. CameraCamera是Android framework ...

  8. call_grant_sel.sql

    set echo offpromptprompt =========================================================================== ...

  9. oracle中的赋权

    1 怎么给用户赋权限 grant create view to scott; (create view 是权限的名称) 2 怎么给用户撤销权限 revoke create view from scot ...

  10. Cells Not Under Attack

    Cells Not Under Attack Vasya has the square chessboard of size n × n and m rooks. Initially the ches ...