会什摸!就是不行??????????????????????

3,4组数据好弊态!

2 条评论

  • @ 2015-01-16 09:21:13

    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    bool st[11],hash[1024];
    int mp[101][11];
    int n,m;//疾病数,药剂数
    int finish;
    int d[1024][10];
    inline int Hash(bool a[])//二进制转十进制
    {
    int x=1,s=0;
    for(int i=1;i<=n;i++)
    {
    s+=x*a[i];
    x*=2;
    }
    return s;
    }
    void search()
    {
    int t=0,w=0;
    finish=(1<<n)-1;
    hash[0]=1;
    while(t<=w)
    {
    for(int i=1;i<=m;i++)
    {
    for(int j=1;j<=n;j++)
    {
    if(mp[i][j]==1)
    st[j]=1;
    else if(mp[i][j]==-1)
    st[j]=0;
    else st[j]=d[t][j];
    }
    int x=Hash(st);
    if(!hash[x])
    {
    hash[x]=1;
    w++;
    for(int j=1;j<=n;j++)
    d[w][j]=st[j];
    d[w][0]=d[t][0]+1;
    }
    if(hash[finish])
    {
    cout<<d[w][0]<<endl;
    return;
    }
    }
    t++;
    }
    cout<<"The patient will be dead."<<endl;
    }
    int main()
    {
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    for(int j=1;j<=n;j++)
    cin>>mp[i][j];
    search();
    return 0;
    }

  • @ 2015-01-16 09:20:52

    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    bool st[11],hash[1024];
    int mp[101][11];
    int n,m;//疾病数,药剂数
    int finish;
    int d[1024][10];
    inline int Hash(bool a[])//二进制转十进制
    {
    int x=1,s=0;
    for(int i=1;i<=n;i++)
    {
    s+=x*a[i];
    x*=2;
    }
    return s;
    }
    void search()
    {
    int t=0,w=0;
    finish=(1<<n)-1;
    hash[0]=1;
    while(t<=w)
    {
    for(int i=1;i<=m;i++)
    {
    for(int j=1;j<=n;j++)
    {
    if(mp[i][j]==1)
    st[j]=1;
    else if(mp[i][j]==-1)
    st[j]=0;
    else st[j]=d[t][j];
    }
    int x=Hash(st);
    if(!hash[x])
    {
    hash[x]=1;
    w++;
    for(int j=1;j<=n;j++)
    d[w][j]=st[j];
    d[w][0]=d[t][0]+1;
    }
    if(hash[finish])
    {
    cout<<d[w][0]<<endl;
    return;
    }
    }
    t++;
    }
    cout<<"The patient will be dead."<<endl;
    }
    int main()
    {
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    for(int j=1;j<=n;j++)
    cin>>mp[i][j];
    search();
    return 0;
    }

  • 1

信息

ID
1026
难度
6
分类
搜索 | 搜索与剪枝 点击显示
标签
(无)
递交数
3640
已通过
1102
通过率
30%
被复制
17
上传者