跳到正文

题解

题解:SP6562 PRUBALL - Esferas

ingo_dtw约 4 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年8月9日
篇幅
约 4 分钟
题目
SP6562

版本

  1. v2当前
  2. v1

我猜你们都是从初赛过来的。


好了我们回到这个题目。 我们发现可以构造一个等差数列……然后……你发现不好做,所以别把初赛的 You have no egg! 给套进来。


但是,我们可以注意下数据范围:

1≤B≤1001 \le B \le 100,1≤M≤10001 \le M \le 1000

所以我们考虑一个二维动态规划,令 dpi,jdp_{i,j} 为第 ii 个 egg 扔 jj 次能到达的最高楼层,第一次在 hh 层扔,egg 是不是碎了:

  • 碎了:那我们还有 i−1i-1 个蛋和 j−1j-1 次机会能测出 dpi−1,j−1dp_{i-1,j-1} 的状态。
  • 没碎:说明 egg 很硬 那我们还有 ii 个蛋和 j−1j-1 次机会能测出 dpi,j−1dp_{i,j-1} 的状态。

所以动态转移方程为:

dpi,j=dpi−1,j−1+dpi,j−1+1dp_{i,j}=dp_{i-1,j-1}+dp_{i,j-1}+1

AC 记录

Ac Code:

C++
#include <bits/stdc++.h>
using namespace std;
#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc _getchar_nolock
#define pc _putchar_nolock
#endif
#define int long long
#define rint register int
#define R register
#define _ read<int>()
inline bool blank(const char x)
{
    return !(x^10)||!(x^9)||!(x^32)||!(x^13);
}
template<class T>inline T read()
{
    T r=0,f=1;char c=gc();
    while(!isdigit(c))
    {
        if(c=='-') f=-1;
        c=gc();
    }
    while(isdigit(c)) r=(r<<1)+(r<<3)+(c^48),c=gc();
    return f*r;
}
inline void out(int x)
{
    if(x<0) pc('-'),x=-x;
    if(x<10) pc(x+'0');
    else out(x/10),pc(x%10+'0');
}
const int N=1010;
int dp[N][N];
signed main()
{
    rint t=_;
    while(t--)
    {
        rint d=_,n=_,b=_;
        // if(n<=0) puts("You have no egg!!!");
        memset(dp,0,sizeof(dp));
        int ans=114514191810;
        if(n==1)//只有1个egg
        {
            out(d);
            pc(' ');
            out(b);
            pc('\n');
        }
        for(rint i=1;i<=n;i++)
        {
            for(rint j=1;j<=b;j++)
            {
                if(i==1) dp[i][j]=j;
                else dp[i][j]=dp[i-1][j-1]+dp[i][j-1]+1;
                if(dp[i][j]>=b)
                {
                    ans=min(ans,j);
                }
            }
        }
        out(d);
        pc(' ');
        out(ans);
        pc('\n');
    }
    return 0;
}
原文
存档评论1 条抓取于