蓝桥杯 矩阵(dp)

蓝桥杯 矩阵(dp)_第1张图片

 

 多画画图,有注释。 

 // #pragma GCC optimize(2)
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #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 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))