蓝桥杯 矩阵(dp)

 多画画图,有注释。 

 // #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;
}

猜你喜欢

转载自blog.csdn.net/qq_44115065/article/details/109069642