Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Networked path_dp
#include<bits/stdc++.h> #define fast ios_base::sync_with_stdio(false);cin.tie(NULL) using namespace std; #define ll long long #define mod 1000000007 //107*107*1361*1361*10000019 int main() { int n,m; cin>>n>>m; ll a[n+1][m+1],b[n+1][m+1]; for(int i=0;i<n;++i) { for(int j=0;j<m;++j) { long long x; cin>>x; a[i][j]=1; b[i][j] =1; while(x%107==0) { a[i][j]*=2; if(a[i][j]%4==0) break; x/=107; } while(x%1361==0) { a[i][j]*=3; if(a[i][j]%9==0) break; x/=1361; } while(x%10000019==0) { a[i][j]*=5; if(a[i][j]%5==0) break; x/=10000019; } while(x%212072634227239451==0) { a[i][j]*=180; break; a[i][j]/=212072634227239451; } // cout<<a[i][j]<<" "; } } ll x[n][m],y[n][m],dp[n+1][m+1];; for(int i=0;i<n;++i) { for(int j=0;j<m;++j) { x[i][j] =1; y[i][j] =1; if(i ==0 || j==0) { dp[i][j] =1; } else { dp[i][j] =0; } b[i][j] = a[i][j]; } } x[0][0] = a[0][0]; y[0][0] = a[0][0]; for(int i=1;i<n;++i) { x[i][0]= b[i-1][0]*b[i][0]; y[i][0]= b[i-1][0]*b[i][0]; b[i][0]= b[i-1][0]*b[i][0]; } for(int j=1;j<m;++j) { x[0][j]= b[0][j-1]*b[0][j]; y[0][j]= b[0][j-1]*b[0][j]; b[0][j]= b[0][j-1]*b[0][j]; //cout<<x[0][j]<<" "; } /*for(int i=0;i<n;++i) { for(int j=0;j<m;++j) { cout<<dp[i][j]<<" "; } cout<<endl; }*/ for(int i=1;i<n;++i) { for(int j=1;j<m;++j) { //cout<<a[i][j]<<" "; x[i][j] = (x[i][j-1]*a[i][j])%180; y[i][j] = (y[i-1][j]*a[i][j])%180; if(x[i][j] !=0) { dp[i][j] = dp[i][j]+ dp[i-1][j]; } if(y[i][j] !=0) { dp[i][j] = dp[i][j] + dp[i][j-1]; } if(x[i][j] == 0 || y[i][j] ==0) { dp[i][j] = dp[i][j] + dp[i][j-1] -1; } if(x[i][j] == 0 && y[i][j] ==0) { dp[i][j] =0; } //cout<<dp[i][j]<<" ";//<<x[i][j]<<" "; } //cout<<endl; } //cout<<x[0][2]; //cout<<x[n-1][m-1]; cout<<dp[n-1][m-1]; }
run
|
edit
|
history
|
help
0
Stream9
code
next greater palindrome
1
Dar
Reminder
Program
cpp ex 3 - solution
k-tree 431 C
2015(M2)Mod.