SRM 573 div2

Source: Internet
Author: User

250...

500...

1000

No idea during the competition. Instead, I thought of a trick. I wanted to take a cha. Later I found that no one in the room submitted it...

Only the number of pre-processed steps from one point to another, and the complexity of the DP space is too high. Today, I saw how others preprocessed it. I am still very tender...

DP [dx] [dy] [m] indicates the number of cases in which (dx, Dy) is moved by M-step coordinates.

Perform a memory search.

const int MAXN = 55;const int MOD = 1e9+7;int dp[MAXN][MAXN][MAXN];int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};class WolfPackDivTwo {public:    int dfs(int dx, int dy, int m) {        if(dp[dx][dy][m] != -1) return dp[dx][dy][m];        int res = 0;        if(m == 0) {            res = (dx == 0 && dy == 0);        } else {            for(int i = 0; i < 4; ++i) {                int xx = abs(dx + dir[i][0]);                int yy = abs(dy + dir[i][1]);                if(xx + yy > m - 1) continue;                res = (res + dfs(xx, yy, m - 1))%MOD;            }        }        return dp[dx][dy][m] = res;    }    int calc(vector <int> x, vector <int> y, int m) {        int n = x.size(), tx, ty, i, ans = 0;        CL(dp, -1);        for(tx = x[0] - m; tx <= x[0] + m; ++tx) {            for(ty = y[0] - m; ty <= y[0] + m; ++ty) {                int tmp = 1;                for(i = 0; i < n; ++i) {                    int dx = abs(tx - x[i]);                    int dy = abs(ty - y[i]);                    if(dx + dy > m) {tmp = 0; continue;}                    tmp = (tmp*dfs(dx, dy, m))%MOD;                }                ans = (ans + tmp)%MOD;            }        }        return ans;    }};

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.