成对的数量 [英] Number of pairs of sets

查看:72
本文介绍了成对的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从1到K都有N组整数。找出其联合包含所有K元素的对的数量。



我尝试过:



i使用了set_union但它给出了TLE,我该怎么做才能优化它?

There are N sets of integers from 1 to K both inclusive. Find out number of pairs of sets whose union contains all the K elements.

What I have tried:

i have used set_union but its giving TLE , what should i do to optimise it ?

推荐答案

你不需要完全执行每一对的结合:放弃第一个缺失项目的联合计算过程,例如



假设
You don't need to fully perform the union of each pair: abandon the union computing process on first missing item, e.g.

Suppose
k=5, s1 = {1,2,5}, s2 = {1,4}





,因为 3 是在 s1 s2 中都缺少那么你不必完全执行两个集合的联合以发现它们是不好的候选人。



since 3 is missing in both s1 and s2 then you don't have to fully perform the union of the two sets to discover they are bad candidates.


这篇关于成对的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆