蓝桥杯 矩阵(dp)

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-28 11:20   408   0

多画画图,有注释。

 // #pragma GCC optimize(2)
 #include <iostream>
 #include <cstdio>
 #include <algorithm>
 #include <queue>
 #include <cmath>
 #include <string>
 #include <vector>
 #include <stack>
 #include <map>
 #include <sstream>
 #include <cstring>
 #include <set>
 #include <cctype>
 #include <bitset>
 #define IO                       \
     ios::sync_with_stdio(false); \
     // cout.tie(0);
 using namespace std;
//int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e5 + 10;
const int maxm = 2e5 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double pi = acos(-1);
LL dp[2030][1030]; 
int main()
{
 #ifdef WXY
 freopen("in.txt", "r", stdin);
 // freopen("out.txt", "w", stdout);
#endif
 dp[1][1]=1;  // 只有一个位置 放 1 
 for(int i=2;i<=2020;i++) // 当前用了 i 个数字 
 {
  for(int j=1;j<=i;j++) // 第一行放了 j 个数字 
  {
   dp[i][j]+=dp[i-1][j-1]; // 无论如何下一个数字总能放在第一行最右边的位置 
   if(j*2>=i) // 如果第二行放的数字比第一行少 那么 第二行还能多一个位置放数字 
    dp[i][j]+=dp[i-1][j];
   dp[i][j]%=2020;
  }
 }
 cout<<dp[2020][1010];// 用了前2020个数字,第一行放了1010个数字 
 return 0;
}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP