动态规划专项intermediate:UVa 10981

直接用map记录状态,1表示该状态可以达到目标状态,0表示不能。然后从左到右dfs,然后一旦得到的返回值为1,就记录路径,然后返回。记录路径也可以用map来实现。本来以为用stl会很慢,结果也只跑了19ms。

#include 
#include 
#include 
#include 
using namespace std;
string s,t;
map dp;
map path;
int dfs(string st)
{
    if(dp.count(st)) return dp[st];
    if(st.size()==t.size())
    {
        if(st==t) return 1;
        else return 0;
    }
    for(int i=0;i>T;
    while(T--)
    {
        dp.clear();
        path.clear();
        cin>>s>>t;
        if(s.size()


你可能感兴趣的:(动态规划)