亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > C++ > 正文

Round C APAC Test 2017 Problem A. Monster Path (C++)

2019-11-08 01:12:36
字體:
來源:轉載
供稿:網友

PRoblem

Codejamon is a mobile game in which monster trainers walk around in the real world to catch monsters. You have an old smartphone with a short battery life, so you need to choose your path carefully to catch as many monsters as possible.

Suppose the Codejamon world is a rectangular grid with R rows and C columns. Rows are numbered from top to bottom, starting from 0; columns are numbered from left to right, starting from 0. You start in the cell in the Rsth row and the Csth column. You will take a total of S unit steps; each step must be to a cell sharing an edge (not just a corner) with your current cell.

Whenever you take a step into a cell in which you have not already caught a monster, you will catch the monster in that cell with probability P if the cell has a monster attractor, or Q otherwise. If you do catch the monster in a cell, it goes away, and you cannot catch any more monsters in that cell, even on future visits. If you do not catch the monster in a cell, you may still try to catch the monster on a future visit to that cell. The starting cell is special: you have no chance of catching a monster there before taking your first step.

If you plan your path optimally before making any move, what is the maximum possible expected number of monsters that you will be able to catch?

The battery can only support limited steps, so hurry up! Input

The first line of the input gives the number of test cases, T. T test cases follow.

Each test case starts with a line of five integers: R, C, Rs, Cs and S. R and C are the numbers of rows and columns in the grid; Rs and Cs are the numbers of the row and column of your starting position, and S is the number of steps you are allowed to take.

The next line contains two decimals P and Q, where P is the probability of meeting a monster in cells with a monster attractor, and Q is the probability of meeting a monster in cells without a monster attractor. P and Q are each given to exactly four decimal places.

Each of the next R lines contains contains C space-separated characters; the j-th character of the i-th line represents the cell at row i and column j. Each element is either . (meaning there is no attractor in that cell) or A (meaning there is an attractor in that cell).

Output

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the largest possible expected number of monsters that the player can catch in the given amount of steps.

y will be considered correct if y is within an absolute or relative error of 10-6 of the correct answer. See the FAQ for an explanation of what that means, and what formats of real numbers we accept.

Limits

1 ≤ T ≤ 100. 0 ≤ Rs < R. 0 ≤ Cs < C. 0 ≤ Q < P ≤ 1. Small dataset

1 ≤ R ≤ 10. 1 ≤ C ≤ 10. 0 ≤ S ≤ 5. Large dataset

1 ≤ R ≤ 20. 1 ≤ C ≤ 20. 0 ≤ S ≤ 9.

分析:

廣度優先算法。遞歸進行,每步記錄:當前剩余步數step、當前期望值cur、當前位置(i, j)、當前訪問過的網格狀態visited。一旦剩余步數為step==0,則將cur與全局result相比,取大值。每一步向上、下、左、右4個方向遞歸(注意越界),并在cur上加上相應可能性,調整當前位置,更新網格狀態visited,即在當前位置上+1,說明該位置訪問過過visited[i][j]次(計算要加上的相應可能性時需要用)。計算每步cur的增量:假設該位置之前訪問過x次。若有attractor,則當前增量=[(1-P)^(x)]*P, 其中[(1-P)^(x)]表示之前x次沒抓到monster的概率。若無attractor,則相應增量=[(1-Q)^x]*Q

代碼:Github

#include <iostream>#include <cmath>#include <vector>#include <stack>#include <queue>#include <algorithm>#include <fstream>#include <iomanip>using namespace std;typedef long long ll;int T;int R, C, Rs, Cs, S;double p;double q;double result = 0;void solve(double cur, int i, int j, int step, vector<vector<char>>game, vector<vector<int>> visited) { if (step == 0) { result = max(result, cur); return; } if (i - 1 >= 0) { visited[i - 1][j]++; if (game[i - 1][j] == '.') solve(cur + pow((1 - q), (double)(visited[i - 1][j]) - 1)*q, i - 1, j, step - 1, game, visited); else solve(cur + pow((1 - p), (double)(visited[i - 1][j]) - 1)*p, i - 1, j, step - 1, game, visited); visited[i - 1][j]--; } if (j - 1 >= 0) { visited[i][j - 1]++; if (game[i][j - 1] == '.') solve(cur + pow((1 - q), (double)(visited[i][j - 1]) - 1)*q, i, j - 1, step - 1, game, visited); else solve(cur + pow((1 - p), (double)(visited[i][j - 1]) - 1)*p, i, j - 1, step - 1, game, visited); visited[i][j - 1]++; } if (i + 1 < R) { visited[i + 1][j]++; if (game[i + 1][j] == '.') solve(cur + pow((1 - q), (double)(visited[i + 1][j]) - 1)*q, i + 1, j, step - 1, game, visited); else solve(cur + pow((1 - p), (double)(visited[i + 1][j]) - 1)*p, i + 1, j, step - 1, game, visited); visited[i + 1][j]--; } if (j + 1 <C) { visited[i][j + 1]++; if (game[i][j + 1] == '.') solve(cur + pow((1 - q), (double)(visited[i][j + 1]) - 1)*q, i, j + 1, step - 1, game, visited); else solve(cur + pow((1 - p), (double)(visited[i][j + 1]) - 1)*p, i, j + 1, step - 1, game, visited); visited[i][j + 1]++; }}int main() { ifstream f_input; ofstream f_output; f_input.open("A-large-practice.in"); f_output.open("out_put"); f_input >> T; for (int tt = 1; tt <= T; tt++) { result = 0; f_input >> R >> C >> Rs >> Cs >> S; f_input >> p >> q; vector<vector<char>> game(R, vector<char>(C, '.')); for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) f_input >> game[i][j]; vector<vector<int>> visited(R, vector<int>(C, 0)); solve(0, Rs, Cs, S, game, visited); f_output << "Case #" << tt << ": "; f_output.setf(ios::fixed, ios::floatfield); f_output << setprecision(7); f_output<< result << endl; cout << tt << "finished" << endl; } f_input.close(); f_output.close();}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国内精品久久久久影院 日本资源| 久久久噜久噜久久综合| 亚洲人午夜色婷婷| 日韩电影免费观看在线观看| 久久99热这里只有精品国产| 国产精品偷伦视频免费观看国产| 亚洲成人激情视频| 亚洲图中文字幕| 中文字幕亚洲字幕| 欧美午夜丰满在线18影院| 国产精品视频内| 亚洲美女性生活视频| 这里只有精品视频在线| 红桃视频成人在线观看| 国内免费久久久久久久久久久| 亚洲综合最新在线| 亚洲国产精品成人精品| 亚洲人成电影在线| 国产精品精品久久久久久| 成人午夜一级二级三级| 欧美中文字幕视频在线观看| 欧美视频在线视频| 亚洲人成毛片在线播放| 久久全国免费视频| 国产精品久久久久久婷婷天堂| 欧美国产精品人人做人人爱| 91免费福利视频| 国产精品久久久久久久电影| 欧美中文字幕在线观看| 亚洲jizzjizz日本少妇| 亚洲在线免费观看| 亚洲人成电影在线观看天堂色| 欧美一区二区三区免费视| 欧美老女人xx| 亚洲精品日韩久久久| 日本久久久久久久| 亚洲最大成人免费视频| 国产精品扒开腿爽爽爽视频| 中文字幕日韩免费视频| 最近2019中文字幕第三页视频| 国产欧美在线观看| 精品视频—区二区三区免费| 亚洲国产精品成人va在线观看| 国产欧美日韩精品丝袜高跟鞋| 伊人久久久久久久久久久| 日韩欧美国产免费播放| 国产精品欧美日韩一区二区| 日韩网站免费观看| 国产一区二区三区久久精品| 黄色精品一区二区| 久99九色视频在线观看| 91色精品视频在线| 久久久久久综合网天天| 国产精品扒开腿做爽爽爽男男| 精品福利一区二区| 欧美性xxxxx极品| 在线免费看av不卡| 91久久嫩草影院一区二区| 欧美性猛交xxxx免费看久久久| 国产在线视频2019最新视频| 久久五月天色综合| 国产日韩中文字幕在线| 97成人精品视频在线观看| 亚洲色无码播放| 欧美亚洲另类制服自拍| 国产精品久久久久久久久粉嫩av| 一区二区三区国产视频| 欧美亚洲午夜视频在线观看| 欧美成人手机在线| 亚洲白拍色综合图区| 亚洲欧美日韩在线一区| 51色欧美片视频在线观看| 奇米四色中文综合久久| 亚洲欧美一区二区三区情侣bbw| 国产亚洲欧美aaaa| 国产成人拍精品视频午夜网站| 国产亚洲精品久久久| 欧美性xxxx极品hd满灌| 久久影视电视剧免费网站| 亚洲国产精品999| 国产女人精品视频| 亚洲人成在线观看网站高清| 美女性感视频久久久| 裸体女人亚洲精品一区| 日韩综合视频在线观看| 97久久精品国产| 欧美性videos高清精品| 欧美电影免费观看高清完整| 国产成人啪精品视频免费网| 精品国产乱码久久久久酒店| 国产精品爽爽ⅴa在线观看| 亚洲国产精品嫩草影院久久| 国产精品69av| 欧美成人精品在线| 国产精品入口夜色视频大尺度| 亚洲一区二区免费在线| 日韩欧美成人区| 国产精品99久久久久久久久久久久| 亚洲成人性视频| 亚洲视频在线视频| 国产精品香蕉av| 欧美专区福利在线| 国产亚洲精品久久久久久| 亚洲激情视频在线观看| 成人h片在线播放免费网站| 超薄丝袜一区二区| 亚洲人成网7777777国产| 日本一区二区三区在线播放| 777777777亚洲妇女| 久久成人人人人精品欧| 国产成人一区二区三区电影| 日韩中文字幕在线精品| 97超级碰碰碰| 26uuu亚洲国产精品| 国外色69视频在线观看| 91国产在线精品| 97在线观看免费| 欧美激情国产精品| 欧美猛交ⅹxxx乱大交视频| 亚洲韩国欧洲国产日产av| 欧美精品生活片| 久久久国产一区二区三区| 亚洲国产成人精品久久| 色综合天天狠天天透天天伊人| 亚洲一区中文字幕| 国产日本欧美视频| 日韩av观看网址| 亚洲一区国产精品| 久久久久国产精品免费网站| 色偷偷av一区二区三区| 亚洲欧美日韩国产中文| 亚洲欧美激情四射在线日| 国产丝袜一区二区三区| 国产做受69高潮| 亚洲精品电影在线| 欧美成人四级hd版| 日韩精品视频在线观看免费| 亚洲大尺度美女在线| 欧美大片大片在线播放| 亚洲国产精品视频在线观看| 欧美xxxx14xxxxx性爽| 26uuu亚洲伊人春色| 国产精品视频1区| 亚洲精品二三区| 国产午夜精品美女视频明星a级| 欧美性少妇18aaaa视频| 日本午夜精品理论片a级appf发布| 久久精品一区中文字幕| 欧美高清videos高潮hd| 久久精品国产v日韩v亚洲| 久久久久久国产精品三级玉女聊斋| 高清欧美性猛交xxxx黑人猛交| 日韩在线观看网站| 日韩欧美精品中文字幕| 欧美日韩国产一中文字不卡| 亚洲无线码在线一区观看| 欧美激情亚洲激情| 国产日韩在线看| 亚洲欧美在线免费观看| 国语自产在线不卡| 中文字幕欧美日韩在线| 国产在线久久久| 国产精品r级在线| 亚洲国模精品私拍|