uva 10934—— Dropping water balloons
生活随笔
收集整理的這篇文章主要介紹了
uva 10934—— Dropping water balloons
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:給定K個氣球,然后n層樓的高度,求確定氣球的硬度(站在多高能摔破)
思路:遞推。dp(i,j)表示最優,那么即dp(i-1,j-1)+1最優,如果K層沒有破,則把K+1看成1層繼續。得到轉移方程dp(i,j)=k+dp(i,j-1)=dp(i-1,j-1)+dp(i,j-1);
code:
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <sstream> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <map> #include <set> #include <bitset>using namespace std;typedef long long ll; typedef unsigned long long ull; typedef long double ld;const int INF=9999999; const int inf=-INF; const int N=125; const int M=2005; const int mod=1000000007; const double pi=acos(-1.0);#define cls(x,c) memset(x,c,sizeof(x)) #define ft(i,s,n) for (int i=s;i<=n;i++) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lrt rt<<1 #define rrt rt<<1|1 #define middle int m=(r+l)>>1 #define lowbit(x) (x&-x) #define pii pair<int,int> #define mk make_pair #define IN freopen("in.txt","r",stdin); #define OUT freopen("out.txt","w",stdout);int k,ans; ll n,dp[N][N]; int main() {while (~scanf("%d%lld",&k,&n),k){cls(dp,0);k=min(k,63);ans=-1;ft(i,1,63) ft(j,1,63)dp[i][j]=dp[i-1][j-1]+1+dp[i][j-1];ft(i,1,63)if (dp[k][i]>=n) {ans=i;break;}if(ans>-1) printf("%d\n",ans);else puts("More than 63 trials needed.");} }總結
以上是生活随笔為你收集整理的uva 10934—— Dropping water balloons的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 输卵管堵塞排卵期疼吗
- 下一篇: uva 12105——Bigger i