14 solutions

  • 0
    @ 2022-1-17 17:41:57

    方法一:暴力法(会超时),可以算出来后直接输出答案

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    ll n,e,ans;
    int main()
    {
    	for(ll a=1;a<=2021;++a)
    	{
    		for(ll b=1;b<=2021;++b)
    		{
    			for(ll c=1;c<=2021;++c)
    			{
    				ll d=2021-a-b-c;
    				if(d>=2) ans+=d-1;//d-1种分解方法(难点)
    				else break;
    			}
    		}
    	}
    	cout<<ans<<"\n";
    	//ans = 691677274345
    	return 0;
    }
    

    方法二;找规律(隔板法)

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    ll ans=1,b;
    int main()
    {
    	b=1;
    	for(int a=2020;a>=2017;--a)
    	{
    		ans*=a;
    		ans/=b;
    		b++;
    	}
    	cout<<ans<<"\n";
    	
    	return 0;
    }
    

    Information

    ID
    106
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    6
    Tags
    # Submissions
    504
    Accepted
    163
    Uploaded By