6450 Social Advertising
You have decided to start up a new social networking company. Other existing popular social networks
already have billions of users, so the only way to compete with them is to include novel features no
other networks have.
Your company has decided to market to advertisers a cheaper way to charge for advertisements (ads).
The advertiser chooses which users’ “wall” the ads would appear on, and only those ads are charged.
When an ad is posted on a user’s wall, all of his/her friends (and of course the user himself/herself)
will see the ad. In this way, an advertiser only has to pay for a small number of ads to reach many
more users.
You would like to post ads to a particular group of users with the minimum cost. You already have
the “friends list” of each of these users, and you want to determine the smallest number of ads you have
to post in order to reach every user in this group. In this social network, if A is a friend of B, then B
is also a friend of A for any two users A and B.
Input
The input consists of multiple test cases. The first line of input is a single integer, not more than
10, indicating the number of test cases to follow. Each case starts with a line containing an integer n
(1 ≤ n ≤ 20) indicating the number of users in the group. For the next n lines, the ith line contains the
friend list of user i (users are labelled 1, . . . , n). Each line starts with an integer d (0 ≤ d < n) followed
by d labels of the friends. No user is a friend of himself/herself.
Output
For each case, display on a line the minimum number of ads needed to be placed in order for them to
reach the entire group of users.
Sample Input
2
5
4 2 3 4 5
4 1 3 4 5
4 1 2 4 5
4 1 2 3 5
4 1 2 3 4
5
2 4 5
2 3 5
1 2
2 1 5
3 1 2 4
Sample Output
1
2

题目大意:打广告搞宣传,有许多朋友关系,一个人做一下广告可以让他的n个朋友还有他自己看到。求找最少的做广告的人。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std; const int maxn=;
int n,flag;
vector<int> f[maxn];
int vis[maxn];
int cnt[maxn]; bool is_ok(int s)
{
memset(vis,,sizeof(vis));
int i,j,sum=;
for(i=;i<s;i++)
{
if(!vis[cnt[i]])
{
vis[cnt[i]]=;sum++;
}
for(j=;j<f[cnt[i]].size();j++)
{
if(!vis[f[cnt[i]][j]])
{
vis[f[cnt[i]][j]]=;sum++;
}
}
}
if(sum==n) return ;
return ;
} void dfs(int now,int s,int dep)
{
if(now>n+) return ;
if(s==dep)
{
if(is_ok(s)) flag=;
return ;
}
cnt[s]=now;
dfs(now+,s+,dep);
dfs(now+,s,dep);
}
int main()
{
int t,i,k,p;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=;i<=n;i++) f[i].clear();
for(i=;i<=n;i++)
{
scanf("%d",&k);
while(k--)
{
scanf("%d",&p);
f[i].push_back(p);f[p].push_back(i);
}
}
flag=;
for(i=;i<=n;i++)
{
dfs(,,i);
if(flag) break;
}
printf("%d\n",i);
}
return ;
}

LA 6450 social advertising(dfs剪枝)的更多相关文章

  1. LA 6450 Social Advertising

    [题目] 给一个无向图,每当对某个点操作,该点以及与该点相连的点都获得标记,问标记所有点至少需要操作多少次 输入 第一行为T,表示测试数据组数 每组测试数据第一行为n(1<=n<=20)表 ...

  2. UVALive 6450 Social Advertising DFS解法

    题意:一些人有朋友关系,在某个人的社交网站上投放广告可以被所有该人的直接朋友看到,问最小投放多少个广告使给出的人都看到广告.(n<=20) 解法:看到n的范围可以想到用二进制数表示每个人被覆盖与 ...

  3. LA 6476 Outpost Navigation (DFS+剪枝)

    题目链接 Solution DFS+剪枝 对于一个走过点k,如果有必要再走一次,那么一定是走过k后在k点的最大弹药数增加了.否则一定没有必要再走. 记录经过每个点的最大弹药数,对dfs进行剪枝. #i ...

  4. *HDU1455 DFS剪枝

    Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  5. POJ 3009 DFS+剪枝

    POJ3009 DFS+剪枝 原题: Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16280 Acce ...

  6. poj 1724:ROADS(DFS + 剪枝)

    ROADS Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10777   Accepted: 3961 Descriptio ...

  7. DFS(剪枝) POJ 1011 Sticks

    题目传送门 /* 题意:若干小木棍,是由多条相同长度的长木棍分割而成,问最小的原来长木棍的长度: DFS剪枝:剪枝搜索的好题!TLE好几次,终于剪枝完全! 剪枝主要在4和5:4 相同长度的木棍不再搜索 ...

  8. DFS+剪枝 HDOJ 5323 Solve this interesting problem

    题目传送门 /* 题意:告诉一个区间[L,R],问根节点的n是多少 DFS+剪枝:父亲节点有四种情况:[l, r + len],[l, r + len - 1],[l - len, r],[l - l ...

  9. HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

随机推荐

  1. Understanding NFS Caching

    Understanding NFS Caching Filesystem caching is a great tool for improving performance, but it is im ...

  2. 《队长说得队》第八次团队作业Alpha冲刺

    项目 内容 这个作业属于哪个课程 >>2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 >>实验十二 团队作业8:软件测试与ALPHA冲刺 团队名称 ...

  3. Electron的介绍

    1.1 Electron是什么? 引用官网的一句话: Build cross platform desktop apps with JavaScript, HTML, and CSS 1.2 诞生 技 ...

  4. C语言实现两数相加2018-09-23

    /*给定两个非空链表来表示两个非负整数.位数按照逆序方式存储,它们的每个节点只存储单个数字.将两数相加返回一个新的链表. 你可以假设除了数字 0 之外,这两个数字都不会以零开头. 示例: 输入:(2 ...

  5. phpExcel使用方法二

    require_once './phpexcel/PHPExcel.php'; // 首先创建一个新的对象 PHPExcel object $objPHPExcel = new PHPExcel(); ...

  6. matplotlib学习记录 一

    from matplotlib import pyplot as plt # 先实例一个图片,传入图片参数,10宽,5高,分辨率为80 image = plt.figure(figsize=(10,5 ...

  7. iOS 中的视图函数 init initwithnib viewDidLoad viewWillAppear的总结

    我要总结的函数主要是这几个: UIView *view-如果view还没有被初始化的话,getter方法会先调用[self loadView],如果getter或者setter方法被重写了,子类中的g ...

  8. Counting Cliques HDU - 5952 单向边dfs

    题目:题目链接 思路:这道题vj上Time limit:4000 ms,HDU上Time Limit: 8000/4000 MS (Java/Others),且不考虑oj测评机比现场赛慢很多,但10月 ...

  9. Linux学习-核心与核心模块

    谈完了整个开机的流程,您应该会知道,在整个开机的过程当中,是否能够成功的驱动我们主机的硬 件配备, 是核心 (kernel) 的工作!而核心一般都是压缩文件,因此在使用核心之前,就得要将他解 压缩后, ...

  10. luogu1972 [SDOI2009]HH的项链

    莫队裸题还不带修改 #include <algorithm> #include <iostream> #include <cstdio> #include < ...