CodeCraft-21 and Codeforces Round #711 (Div. 2)

CF1498B Box Fitting

从大到小二进制枚举。。。。

#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<set>
#include<map>
#include<bitset>
#include<unordered_map>
using namespace std;
#define LL long long
#define eps (1e-9)
typedef unsigned long long ull;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const int bas = 131;
const LL mod = 5000011;

int a[50];
int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int n, k, x;
		memset(a, 0, sizeof(a));
		scanf("%d%d", &n, &k);
		for (int i = 1; i <= n; i++)
		{
			scanf("%d", &x);
			int tmp = 0;
			while (x)
			{
				tmp++;
				x /= 2;
			}
			tmp--;
			a[tmp]++;
		}
		int ans = 0;
		while (n)
		{
			ans++;
			int tmp = k;
			for (int i = 30; i >= 0; i--)
			{
				while (tmp > 0 && a[i] > 0 && tmp >= (1 << i))
				{
					tmp -= (1 << i);
					a[i]--;
					n--;
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

CF1498C Planar Reflections

dp题,dp[i][j]表示有i个隔板,j年龄时的数量。
状态转移为dp[i][j]=dp[i-1][j]//上一个传过来时j是不变的 + dp[n-1][j-1] //因为撞到后一个所以传回来是j-1.

#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<set>
#include<map>
#include<bitset>
#include<unordered_map>
using namespace std;
#define LL long long
#define eps (1e-9)
typedef unsigned long long ull;

const int maxn = 1e3 + 10;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const int bas = 131;
const LL mod = 1e9 + 7;

LL dp[maxn][maxn];
int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int n, k;
		scanf("%d%d", &n, &k);
		for (int i = 0; i <= n; i++)dp[i][1] = 1;
		for (int i = 1; i <= k; i++)dp[0][i] = 1;
		for (int j = 1; j <= k; j++)
		{
			for (int i = 1; i <= n; i++)
			{
				dp[i][j] = (dp[i - 1][j] + dp[n - i][j - 1]) % mod;
			}
		}
		printf("%lld\n", dp[n][k]);
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值