Advertisement
saurav_kalsoor

MLE

May 22nd, 2021
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define MOD 1000000007
  4.  
  5. using namespace std;
  6.  
  7. void solve(){
  8. int n, m, k;
  9. cin>>n>>m>>k;
  10.  
  11. vector<vector<int>> dp(n, vector<int>(m, 1));
  12. for(int i=1;i<n;i++){
  13. for(int j=1;j<m;j++){
  14. dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
  15. }
  16. }
  17.  
  18. ll res = 0;
  19. int x,y,p;
  20. while(k--){
  21. cin>>x>>y>>p;
  22. res = (res + dp[x-1][y-1]*p)%MOD;
  23. }
  24. cout<<res<<endl;
  25. }
  26.  
  27. signed main() {
  28. ios_base::sync_with_stdio(false);
  29. cin.tie(NULL);
  30.  
  31. int t;
  32. cin>>t;
  33. while(t--)
  34. solve();
  35. }
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement