题解:SP6562 PRUBALL - Esferas

· · 题解

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

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

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

1 \le B \le 100$,$1 \le M \le 1000

:::

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

所以动态转移方程为:

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

AC 记录

Ac Code:

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