posts - 74,  comments - 33,  trackbacks - 0

Description

What is the maximum number of edges in an undirected graph G of n vertices that avoids a k-matching? Note that loops and parallel edges are not allowed in the graph.

Input

The input contains several test cases.
For each test case, there is one line with two positive integers, n ≤ 1000 and k ≤ 1000.
The input ends with two zeroes.

Output

For each test case output the maximum number of edges.

Sample Input

1000 1
500 2
0 0

Sample Output

0
499
图论中的匹配问题!K边匹配问题
开始的时候一直考虑少了一种情况。。。。
我的思路是:
生成图 因为是最大K匹配所以生成的图有两类;
1.   图中不存在断点也就是说所有的点存在在一个连通分量里。例如
6 2 我们首先选择一个点标记为1从1像另外5个点生成边机5条边。而要继续生成边的话就会出现2匹配,与题意不符。可以证明在这类生成边中 n k
符合(n-1)+(n-2)+……+(n-k+1)及等差数列也可以认为是C(n,k);
2.  此类生成图就是存在断点,我们知道图中无重边,无自环所以一个N个点的简单图最大有才C(n,2)条边。而从最大二分匹配中得知一个n点图,最大会出现k匹配
反向思维我们知道如果给出n k,当n>2*k我们可以选择n中的2k个点构造一个子完全图(存在断点),然后生成的边符合最大不超过k匹配。
最后比较1和2两类生成边数,取max,极为本题答案!
1  4518669(3)  xujiaming  132K  0MS  C++  280B 
posted on 2008-12-28 15:49 KNIGHT 阅读(440) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2009年5月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(8)

随笔档案

文章档案

Friends

OJ

搜索

  •  

最新评论

阅读排行榜

评论排行榜