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. Jquery的parent和parents(找到某一特定的祖先元素)

    关于Jquery的parent和parents parent是指取得一个包含着所有匹配元素的唯一父元素的元素集合.parents则是取得一个包含着所有匹配元素的祖先元素的元素集合(不包含根元素).可以 ...

  2. HTML5编程之旅系列一:HTML5 Geolocation 初探

    让我们假设这样一个场景,有一个web应用程序,它可以向用户提供附近不远处某商场的打折优惠信息.使用HTML5 Geolocation API(地理定位 API),可以请求用户共享他们的位置信息. HT ...

  3. oracle10g遇到ORA-16038日志无法归档问题

    SQL> shutdown immediate ORA-01109: 数据库未打开 已经卸载数据库. ORACLE 例程已经关闭. SQL> startup ORACLE 例程已经启动. ...

  4. java 数据结构 队列的实现

    java 数据结构队列的代码实现,可以简单的进行入队列和出队列的操作 /** * java数据结构之队列的实现 * 2016/4/27 **/ package cn.Link; import java ...

  5. climit 头文件的内容

    int.long和long long C++的short.int.long和long long类型通过使用不同数目的位来存储值(关于位的概念自行了解),最多能够表示4中不同的整数宽度.C++提供了一种 ...

  6. JDBC的超时原理

    1.什么是JDBC jdbc是业务系统连接数据的标准API.SUN公司一共定义了4中类型的JDBC:JDBC-ODBC桥:Native-API 驱动:Network-Protocol 驱动:Datab ...

  7. Hibernate锁机制

    业务逻辑的实现过程中,往往需要保证数据访问的排他性.因此,我们就需要通过一些机制来保证这些数据在某个操作过程中不会被外界修改,这样的机制,在这里,也就是所谓的“锁”,即给我们选定的目标数据上锁,使其无 ...

  8. Opencv 图像叠加 添加水印

    Opencv 图像叠加 添加水印 C++: void Mat::copyTo(OutputArray m) const C++: void Mat::copyTo(OutputArray m, Inp ...

  9. Linux运维常用的命令详解

    1. 查看系统内核版本 [root@funsion geekxa]# cat /etc/issue CentOS release 6.5 (Final) Kernel \r on an \m 显示了系 ...

  10. jvisualvm

    f the fonts used by VisualVM are hard to read, switching the LaF might help.  Try for example  'visu ...