<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) E. Rock Is Push dp

      E. Rock Is Push

      You are at the top left cell (1,1) of an n×m labyrinth. Your goal is to get to the bottom right cell (n,m). You can only move right or down, one cell per step. Moving right from a cell (x,y) takes you to the cell (x,y+1), while moving down takes you to the cell (x+1,y).

      Some cells of the labyrinth contain rocks. When you move to a cell with rock, the rock is pushed to the next cell in the direction you're moving. If the next cell contains a rock, it gets pushed further, and so on.

      The labyrinth is surrounded by impenetrable walls, thus any move that would put you or any rock outside of the labyrinth is illegal.

      Count the number of different legal paths you can take from the start to the goal modulo 109+7. Two paths are considered different if there is at least one cell that is visited in one path, but not visited in the other.

      Input

      The first line contains two integers n,m — dimensions of the labyrinth (1≤n,m≤2000).

      Next n lines describe the labyrinth. Each of these lines contains m characters. The j-th character of the i-th of these lines is equal to "R" if the cell (i,j) contains a rock, or "." if the cell (i,j) is empty.

      It is guaranteed that the starting cell (1,1) is empty.

      Output

      Print a single integer — the number of different legal paths from (1,1) to (n,m) modulo 109+7.

      Examples

      input
      1 1
      .
      output
      1
      input
      2 3
      ...
      ..R
      output
      0
      input
      4 4
      ...R
      .RR.
      .RR.
      R...
      output
      4

      Note

      In the first sample case we can't (and don't have to) move, hence the only path consists of a single cell (1,1).

      In the second sample case the goal is blocked and is unreachable.

      Illustrations for the third sample case can be found here: https://subdomain.codeforc.es/menci/assets/rounds/1225/index.html

      題意

      一個n*m的矩陣,里面有一堆箱子,你可以推箱子,連續的箱子你也能推動。

      問你從(1,1)到(n,m)有多少種不同路徑的方案個數。

      題解

      定義:
      dp[i][j][0]表示從(i,j)往下走到達終點的方案數。
      dp[i][j][1]表示從(i,j)往右走到達終點的方案數。

      比較顯然的
      dp[i][j][0]=dp[i+1][j][1]+dp[i+2][j][1]+....+dp[i+x][j][1],直到(i+x+1,j)是一個箱子推到底了,不能再推箱子了。

      同理dp[i][j][1]也是如此。

      顯然后面這坨可以用前綴和優化一下,然后就可以變成n^2的dp轉移了。

      代碼

      #include<bits/stdc++.h>
      using namespace std;
      const int maxn = 2005;
      int n,m;
      const int mod = 1e9+7;
      char a[maxn][maxn];
      // 0 for down;1 for right
      int num[maxn][maxn][2],dp[maxn][maxn][2],sum[maxn][maxn][2];
      int main(){
      	scanf("%d%d",&n,&m);
      	for(int i=1;i<=n;i++){
      		scanf("%s",a[i]+1);
      	}
      	if(n==1&&m==1&&a[1][1]=='.'){
      		cout<<"1"<<endl;
      		return 0;
      	}
      	if(a[1][1]=='R'||a[n][m]=='R'){
      		cout<<"0"<<endl;
      		return 0;
      	}
      	for(int i=n;i>=1;i--){
      		for(int j=m;j>=1;j--){
      			if(a[i][j]=='R'){
      				num[i][j][0]+=1;
      				num[i][j][1]+=1;
      			}
      			num[i][j][0]+=num[i+1][j][0];
      			num[i][j][1]+=num[i][j+1][1];
      		}
      	}
      	dp[n][m][0]=1;dp[n][m][1]=1;sum[n][m][0]=1;sum[n][m][1]=1;
      	for(int i=n;i>=1;i--){
      		for(int j=m;j>=1;j--){
      			if(i==n&&j==m)continue;
      			dp[i][j][0]=(sum[i+1][j][0]-sum[n-num[i+1][j][0]+1][j][0])%mod;
      			dp[i][j][1]=(sum[i][j+1][1]-sum[i][m-num[i][j+1][1]+1][1])%mod;
      			sum[i][j][0]=(sum[i+1][j][0]+dp[i][j][1])%mod;
      			sum[i][j][1]=(sum[i][j+1][1]+dp[i][j][0])%mod;
      		}
      	}
      	cout<<(dp[1][1][0]+dp[1][1][1]+2ll*mod)%mod<<endl;
      }
      
      posted @ 2019-11-02 14:03  qscqesze  閱讀(352)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 91亚洲国产三上悠亚在线播放| 婷婷五月综合激情| 国内精品久久人妻无码不卡| 久久精品国产亚洲av热一区| 欧美极品色午夜在线视频| 亚洲一区中文字幕第十页| 99久久无码私人网站| 中文字幕人妻日韩精品| 中文熟妇人妻av在线| 1000部拍拍拍18勿入免费视频| 免费人成年激情视频在线观看| 久久精品亚洲成在人线av麻豆| 久久夜色精品国产亚洲av| 四虎成人精品无码| 熟女人妻aⅴ一区二区三区电影| 深夜福利视频在线播放| 人妻少妇精品视频三区二区| 国产偷窥熟女高潮精品视频| 亚洲欧洲精品日韩av| 久久精品免视看国产成人| 好男人视频www在线观看| 伊伊人成亚洲综合人网7777| 韩国午夜福利片在线观看| 亚洲人成亚洲人成在线观看| 久久久久香蕉国产线看观看伊| 九九热免费公开视频在线| 40岁大乳的熟妇在线观看| 国产玩具酱一区二区三区| 国产激情一区二区三区四区| 精品人妻少妇一区二区三区| 国产最大成人亚洲精品| 亚洲熟妇色自偷自拍另类| 永久无码天堂网小说区| 少妇内射高潮福利炮| 思思热在线视频精品| 蜜芽久久人人超碰爱香蕉| 铜梁县| 四虎永久在线精品无码视频| 美女爽到高潮嗷嗷嗷叫免费网站| 国产精品毛片一区二区三| 亚洲国产精品一区二区视频|