칼날 부채 (KNIVES) 문제에 대해 질문있습니다.

  • iyaa
    iyaa

    https://algospot.com/judge/problem/read/KNIVES

    기초적인 DP문제라 생각하여 건드리고 있습니다만, 어디가 도대체 문제인지 몰라서 질문드립니다.
    점화식 자체는 (공격,이동,대기)중 최대인것만 선택하는 식으로 하고있고, 공격은 현재 쿨타임이 0초 이하일때만 가능하게 했습니다.

    사실..너무 간단하게 생각했는데 오답이 계속 나오니 어디가 어떻게 문제인지 아예 접근 자체가 힘들군요....
    고수분들의 답변 요청합니다 ㅜㅜ

    아래는 코드입니다.

    #define _CRT_SECURE_NO_WARNINGS
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<sstream>
    #include<string>
    #include<vector>
    #include<cmath>
    #include<cstdio>
    #include<cstdlib>
    #include<fstream>
    #include<cassert>
    #include<numeric>
    #include<set>
    #include<map>
    #include<queue>
    #include<list>
    #include<deque>
    #include<stack>
    #define INF 1987654321
    using namespace std;
    vector<int> dy;
    vector<int> dx;
    bool isbound(vector<string>& field, int y, int x){
        if (y < 0){ return false; }
        if (x < 0){ return false; }
        if (y >= field.size()){ return false; }
        if (x >= field[0].size()){ return false; }
        if (field[y][x] == 'x'){ return false; }
        return true;
    }
    int dist(int y, int x, int y2, int x2){
        return abs(y2 - y) + abs(x2 - x);
    }
    int dmg(int A, char c){
        if (c < '0'){ return false; }
        if (c > '9'){ return false; }
        int B = c - '0';
        return max(0, (A - B));
    }
    int attack(vector<string>& field, int L, int A, int x, int y){
        int ret = 0;
        for (int y2 = 0; y2<field.size(); y2++){
            for (int x2 = 0; x2<field[0].size(); x2++){
                if (!isbound(field, y2, x2)){ continue; }
                if (dist(y, x, y2, x2) > L){ continue; }
                ret += dmg(A, field[y2][x2]);
            }
        }
        return ret;
    }
    void calcattack(int A, int L, vector<string>& field, vector<vector<int> >& attackcache){
        for (int y2 = 0; y2 < field.size(); y2++){
            for (int x2 = 0; x2 < field[0].size(); x2++){
                attackcache[y2][x2] = attack(field, L, A, y2, x2);
            }
        }
    }
    int solve(vector<string>& field, int L, int A, int CT, int TL, int nowy, int nowx, bool swt, int nowcool, vector<vector<vector<vector<int> > > >& cache, vector<vector<int> >& attackcache)
    {
        if (!isbound(field, nowy, nowx)){ return 0; }
        if (TL <= 0){ return 0; }
        int& ret = cache[TL][nowy][nowx][swt];
        if (ret != -1){ return ret; }
        ret = 0;
        if (nowcool <= 0){
            for (int i = 0; i < 5; i++){
                int y2 = nowy + dy[i];
                int x2 = nowx + dx[i];
                if (!isbound(field, y2, x2)){ continue; }
                ret = max(ret, solve(field, L, A, CT, TL - 1, y2, x2, 0, max(0, nowcool - 1), cache, attackcache));
                ret = max(ret, solve(field, L, A, CT, TL - 1, nowy, nowx, 1, CT, cache, attackcache) + attackcache[nowy][nowx]);
            }
        }
        else{
            for (int i = 0; i < 5; i++){
                int y2 = nowy + dy[i];
                int x2 = nowx + dx[i];
                if (!isbound(field, y2, x2)){ continue; }
                ret = max(ret, solve(field, L, A, CT, TL - 1, y2, x2, 0, max(0, nowcool - 1), cache, attackcache));
            }
        }
        return ret;
    }
    int main(){
        dy.push_back(0);
        dy.push_back(-1);
        dy.push_back(0);
        dy.push_back(1);
        dy.push_back(0);
    
        dx.push_back(-1);
        dx.push_back(0);
        dx.push_back(1);
        dx.push_back(0);
        dx.push_back(0);
        int T;
        cin >> T;
        while (T--){
            int H, W, L, A, CT, TL;
            cin >> H >> W >> L >> A >> CT >> TL;
            int Y = H;
            int X = W;
            vector<string> field;
            for (int i = 0; i < Y; i++){
                string s;
                cin >> s;
                field.push_back(s);
            }
            vector<vector<int> > attackcache(Y, vector<int>(X, 0));
            vector<vector<vector<vector<int> > > > cache(TL + 10, vector<vector<vector<int> > >(Y + 10, vector<vector<int> >(X + 10, vector<int>(2, -1))));
            calcattack(A, L, field, attackcache);
            int ret = solve(field, L, A, CT, TL, 0, 0, 0, 0, cache, attackcache);
            cout << ret << endl;
        }
        system("pause");
    }
    


    8년 전
0개의 댓글이 있습니다.
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.