예제 #1
0
int main(){
    ios::sync_with_stdio(0);
    int count=0;
    while(cin >> n && n){
        cout << "**********************************************************\n";
        cout << "Network #"<<++count << endl;
        dist.clear();
        dist.resize(n,vd(n));
        memset(memo,-1,sizeof memo);
        X.clear();X.resize(n);
        Y.clear();Y.resize(n);
        for (int i = 0; i < n; ++i) {
            cin >> X[i] >> Y[i];
        }
        for (int j = 0; j < n; ++j) {
            for (int i = j+1; i < n; ++i) {
                dist[j][i]= dist[i][j] = dis(j,i);
                //cerr << "dist " << j << "  " << i <<"  ->   "<< dist[j][i] << endl;
            }
        }

        double ans = inf; int id =-1;
        for (int k = 0; k < n; ++k) {
            double val = tsp(k,(1<<k));
            //cerr << val << endl;
            if(val < ans) ans = val,id=k;
        }
        //id=0;
        //cerr << id << endl;
        int msk=0;
        while(--n) {
                msk |= (1 << id);
            if(dis(id,par[id][msk])!=16) {
                printf("Cable requirement to connect (%d,%d) to (%d,%d) is %.2lf feet.\n", X[id], Y[id], X[par[id][msk]], Y[par[id][msk]], dis(id, par[id][msk]) );
                id = par[id][msk];
            }
        }
        printf("Number of feet of cable required is %.2lf.\n",ans);
    }

    return 0;
}
예제 #2
0
int main() {
    inp(t);
    A.resize(26);
    string s,s1;
    for(int i=0;i<26;i++)
        A[i].resize(26);

    while(t--) {
        inp(n);
        inp(k);
        cin>>s;
        for(int i=0;i<26;i++)
            for(int j=0;j<26;j++)
                cin>>A[i][j];

        A=power(A,k);

        double ans=0;
        map<string,int> m;
        for(int i=0;i<n;i++) {
            cin>>s1;
            if(s.length()!=s1.length())
                continue;
            if(m.find(s1)!=m.end())
                continue;
            m[s1]=1;
            // cout<<s<<" "<<s1<<endl;
            double val=1;
            for(int i=0;i<s.length();i++) {
                val*=A[s[i]-'a'][s1[i]-'a'];
            }
            ans+=val;
        }
        printf("%.6f\n", ans);
    }
     
    return 0;
}