CodeForces 1093A Dice Rolling

版权声明:博主的博客不值钱随便转载但要注明出处 https://blog.csdn.net/easylovecsdn/article/details/85028187

题意:

一个骰子6个面(点数2——7),现在想拼凑一个数x(一定可以)问你要投多少次。

思路:
递推,dp[i]代表x = i要投的次数,i <= 7有dp[i] = 1,否则dp[i]  = dp[i - 2] + dp[2]。

Code

#include <bits/stdc++.h>

using namespace std;

const int maxn = 105;
int dp[maxn];

int main()
{
	int t, n;
	for (int i = 2; i <= 7; i++) dp[i] = 1;
	for (int i = 8; i <= 100; i++) dp[i] = dp[i - 2] + dp[2];
	cin >> t;
	while (t--)
	{
		cin >> n;
		cout << dp[n] << endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/easylovecsdn/article/details/85028187
今日推荐