zoukankan      html  css  js  c++  java
  • uva11795

    这题说的是一个人要消灭 所有的机器人,但是他有他可以消灭的机器人,他可以通过它消灭的机器人的武器去消灭其他的机器人, 给了一个可以消灭的关系的矩阵,计算消灭这些机器人的顺序的不同方案是多少种 , 刚开始以为是方案数 而不是 消灭的顺序wa

    我们可以知道dp[S] 这个集合的状态可以从 他的子集来, 枚举他的子集,这样可以从不同的子集来,这样我们每个点子被算一次

    首先 要处理每个子集所能 到达的点的情况列举出来 , 进行预处理,得到答案

    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string.h>
    #include <queue>
    using namespace std;
    typedef long long ll;
    const int maxn=20;
    int mto[maxn];
    ll dp[1<<16];
    char s1[maxn];
    int P[1<<16];
    int main(){
        int cas;
        scanf("%d",&cas);
        for(int cc=1; cc<=cas; ++cc){
              int n;
              scanf("%d",&n);
              for(int i=0; i<=n ; ++i){
                   scanf("%s",s1);
                   mto[i]=0;
                   for(int j=0; j<n; ++j)
                         if(s1[j]=='1')
                            mto[i]|=(1<<j);
              }
              for(int S=0;S<(1<<n) ;++S){
                   P[S]=mto[0];
                   for(int i=0; i<n; ++i)
                     if(S&(1<<i))
                        P[S]=P[S]|mto[i+1];
              }
              memset(dp,0,sizeof(dp));
              dp[0]=1;
              for(int S=0; S<(1<<n); ++S){
                   for(int i=0; i<n; ++i)
                   if( ( S&(1<<i) ) &&( P[S^(1<<i)]&(1<<i) ) ){
                       dp[S]+= dp[S^(1<<i)];
                   }
              }
              printf("Case %d: %lld
    ",cc,dp[(1<<n)-1]);
    
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    微信支付
    集成支付宝SDK流程
    使用ASIFormDataRequest完成用户的登录操作
    本地推送UILocalNotification
    iOS 远程推送通知 详解
    iOS 8 中如何集成 Touch ID 功能
    iOS指纹识别Touch ID的安全性探讨
    iOS 支付(含支付宝、银联、微信)
    iOS 社交化分享功能
    Python3内建函数sorted
  • 原文地址:https://www.cnblogs.com/Opaser/p/4057329.html
Copyright © 2011-2022 走看看