当前位置:   article > 正文

蓝桥杯 矩阵(dp)_蓝桥杯矩阵扫描

蓝桥杯矩阵扫描

 

 多画画图,有注释。 

  1. // #pragma GCC optimize(2)
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <algorithm>
  5. #include <queue>
  6. #include <cmath>
  7. #include <string>
  8. #include <vector>
  9. #include <stack>
  10. #include <map>
  11. #include <sstream>
  12. #include <cstring>
  13. #include <set>
  14. #include <cctype>
  15. #include <bitset>
  16. #define IO \
  17. ios::sync_with_stdio(false); \
  18. // cout.tie(0);
  19. using namespace std;
  20. //int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
  21. typedef unsigned long long ULL;
  22. typedef long long LL;
  23. typedef pair<int, int> P;
  24. const int maxn = 2e5 + 10;
  25. const int maxm = 2e5 + 10;
  26. const LL INF = 0x3f3f3f3f3f3f3f3f;
  27. const int inf = 0x3f3f3f3f;
  28. const LL mod = 1e9 + 7;
  29. const double pi = acos(-1);
  30. LL dp[2030][1030];
  31. int main()
  32. {
  33. #ifdef WXY
  34. freopen("in.txt", "r", stdin);
  35. // freopen("out.txt", "w", stdout);
  36. #endif
  37. dp[1][1]=1; // 只有一个位置 放 1
  38. for(int i=2;i<=2020;i++) // 当前用了 i 个数字
  39. {
  40. for(int j=1;j<=i;j++) // 第一行放了 j 个数字
  41. {
  42. dp[i][j]+=dp[i-1][j-1]; // 无论如何下一个数字总能放在第一行最右边的位置
  43. if(j*2>=i) // 如果第二行放的数字比第一行少 那么 第二行还能多一个位置放数字
  44. dp[i][j]+=dp[i-1][j];
  45. dp[i][j]%=2020;
  46. }
  47. }
  48. cout<<dp[2020][1010];// 用了前2020个数字,第一行放了1010个数字
  49. return 0;
  50. }

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/993324
推荐阅读
相关标签
  

闽ICP备14008679号