zoukankan      html  css  js  c++  java
  • [CF478D] Red-Green Towers

    Description

    有红色、绿色两种砖块,分别有 (r,g) 块,要用他们搭建高度最大的金字塔(第 (i) 层恰好有 (i) 块砖),每一层的砖的颜色必须相同,求有多少种方案。

    Solution

    考虑到层数是 (sqrt n) 量级的,因此我们可以简单地 DP,不妨设计算出的层数为 (h),那么这样需要的总砖块数是确定的,不妨记为 (tot)

    (f[i][j]) 表示制作了 (1-i) 层,用了 (j) 块红砖,有多少种方案。

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long 
    const int N = 200005;
    const int mod = 1e+9+7;
    
    int f[N],n,r,g;
    
    signed main()
    {
        ios::sync_with_stdio(false);
    
        cin>>r>>g;
    
        for(int i=1;i<=r+g+1;i++)
        {
            int t=i*(i+1)/2;
            if(t>r+g) 
            {
                n=i-1;
                break;
            }
        }
    
        f[0]=1;
    
        for(int i=1;i<=n;i++)
        {
            for(int j=r;j>=i;j--)
            {
                f[j]=(f[j]+f[j-i])%mod;
            }
        }
    
        int max_r=r;
        int min_r=n*(n+1)/2-g;
    
        int ans=0;
        for(int i=max(0ll,min_r);i<=max_r;i++)
        {
            ans=(ans+f[i])%mod;
        }
    
        cout<<ans<<endl;
    }
    
  • 相关阅读:
    SpringMVC源码阅读(一)
    Struts2技术内幕-----第七章
    1118 Lining Up
    1146 ID Codes
    1056 IMMEDIATE DECODABILITY
    1028 Web Navigation
    1045 Bode Plot
    1083 Moving Tables
    并查集路径压缩
    线段树
  • 原文地址:https://www.cnblogs.com/mollnn/p/14120552.html
Copyright © 2011-2022 走看看