【Codeforces549B】【贪心】Looksery Party

Looksery Party

Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u

Description

The Looksery company, consisting of n staff members, is planning another big party. Every employee has his phone number and the phone numbers of his friends in the phone book. Everyone who comes to the party, sends messages to his contacts about how cool it is. At the same time everyone is trying to spend as much time on the fun as possible, so they send messages to everyone without special thinking, moreover, each person even sends a message to himself or herself.
Igor and Max, Looksery developers, started a dispute on how many messages each person gets. Igor indicates n numbers, the i-th of which indicates how many messages, in his view, the i-th employee is going to take. If Igor guesses correctly at least one of these numbers, he wins, otherwise Max wins.
You support Max in this debate, so you need, given the contact lists of the employees, to determine whether there is a situation where Igor loses. Specifically, you need to determine which employees should come to the party, and which should not, so after all the visitors send messages to their contacts, each employee received a number of messages that is different from what Igor stated.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of employees of company Looksery.
Next n lines contain the description of the contact lists of the employees. The i-th of these lines contains a string of length n, consisting of digits zero and one, specifying the contact list of the i-th employee. If the j-th character of the i-th string equals 1, then the j-th employee is in the i-th employee’s contact list, otherwise he isn’t. It is guaranteed that the i-th character of the i-th line is always equal to 1.
The last line contains n space-separated integers: a1, a2, …, an (0 ≤ ai ≤ n), where ai represents the number of messages that the i-th employee should get according to Igor.

Output

In the first line print a single integer m — the number of employees who should come to the party so that Igor loses the dispute.
In the second line print m space-separated integers — the numbers of these employees in an arbitrary order.
If Igor wins the dispute in any case, print -1.
If there are multiple possible solutions, print any of them.

Samples

Input1

3
101
010
001
0 1 2

Output1

1
1

Input2

1
1
1

Output2

0

Input3

4
1111
0101
1110
0001
1 0 1 0

Output3

4
1 2 3 4

Hint

In the first sample Igor supposes that the first employee will receive 0 messages. Since he isn’t contained in any other contact list he must come to the party in order to receive one message from himself. If he is the only who come to the party then he will receive 1 message, the second employee will receive 0 messages and the third will also receive 1 message. Thereby Igor won’t guess any number.
In the second sample if the single employee comes to the party he receives 1 message and Igor wins, so he shouldn’t do it.
In the third sample the first employee will receive 2 messages, the second — 3, the third — 2, the fourth — 3.

Source

Looksery Cup 2015

这道题一看没有什么思路,但是用贪心可以用一个很巧妙的办法做出来。
如果所有人的a都大于0,那么这个时候就很简单了,每个人都不去就可以了,如果有一个为0的,那么根据题意,每个人自己肯定会给自己发短信,那么我们让这个人去,然后他就不为0了,当然可能会导致其他人变成0,我们就递归处理这个问题,可以证明,实际上这个问题是不会出现什么无解的情况的
所以这样我们就可以用一个 O(n2) 的方法水过去

下面放代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<stack>
#define INF 2100000000
#define ll long long
#define clr(x)  memset(x,0,sizeof(x))
#define clrmax(x)  memset(x,127,sizeof(x))

using namespace std;

inline int read()
{
    char c;
    int ret=0;
    while(!(c>='0'&&c<='9'))
        c=getchar();
    while(c>='0'&&c<='9')
    {
        ret=(c-'0')+(ret<<1)+(ret<<3);
        c=getchar();
    }
    return ret;
}

#define M 105

int a[M],map[M][M];
int ans[M],sta,n;

int main()
{
    n=read();
    for(int i=1;i<=n;i++,getchar())
        for(int j=1;j<=n;j++)
        {
            char c=getchar();
            map[i][j]=c-'0';
        }
    for(int i=1;i<=n;i++)
        a[i]=read();
    for(int i=1;i<=n;i++)
    {
        int k=0;
        for(k=1;k<=n;k++)
            if(a[k]==0)break;
        if(k!=n+1)
        {
            for(int j=1;j<=n;j++)
                if(map[k][j])a[j]--;
            ans[++sta]=k;
        }

    }
    cout<<sta<<'\n';
    sort(ans+1,ans+sta+1);
    for(int i=1;i<=sta;i++)
        printf("%d ",ans[i]);
}

大概就是这个样子,如果有什么问题,或错误,请在评论区提出,谢谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值