ZOJ 3605 Find the Marble

省赛弱爆了,水题都A不调=。=。。。。H,J死的很惨,F题连看都没看上一眼,dp啊,摸都没摸上

View Code
#include<iostream>
#include<cstring>
#include <cstdio>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include <set>
#include<ctime>
#include<cmath>
#include <cstdlib>
#include<algorithm>
#include <iomanip>
#include <bitset>
using namespace std;
using namespace std;
#define LL long long
#define nMax 110
#define mMax 51
LL dp[mMax][mMax][nMax];
pair<LL,LL>  p[100];
int main() {
    LL T,n,m,num,s;
    cin>>T;
    while(T--){
        cin>>n>>m>>num>>s;
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=m;i++){
            cin>>p[i].first>>p[i].second;
        }
        dp[0][0][s]=1;
        for(LL i=1;i<=m;i++){
            for(LL j=0;j<=num&&j<=i;j++){
                if(j){
                    for(LL k=1;k<=n;k++){
                        if(k==p[i].first)
                            dp[i][j][p[i].first]+=dp[i-1][j-1][p[i].second];
                        else if(k==p[i].second)
                            dp[i][j][p[i].second]+=dp[i-1][j-1][p[i].first];
                        else dp[i][j][k]+=dp[i-1][j-1][k];
                    }            
                }
                for(LL k=1;k<=n;k++){
                    dp[i][j][k]+=dp[i-1][j][k];
                    //cout<<dp[i][j][k]<<" ";
                }
                //cout<<"    ";
            }
            //cout<<endl;
        }
        LL maxn=0,ans=-1;
        for(LL i=1;i<=n;i++){
            if(dp[m][num][i]>maxn){
                ans=i;
                maxn=dp[m][num][i];
            }
        }
        cout<<ans<<endl;
    }return 0;
}
posted @ 2012-04-17 22:21  HaoHua_Lee  阅读(313)  评论(0编辑  收藏  举报