3 条题解

  • 1
    @ 2025-5-20 16:50:48
    #include <bits/stdc++.h> 
    using namespace std;
    int n , ans , a[114514] ;
    void f(int n , int last , int step , int k )
    {
    	if ( last > n && n != 0 ) return;
    	if( n == 0 && step > 1 )
    	{
    		ans++;
    		cout << k << "=" ;
    		for( int i = 0 ; i < step - 1 ; i++ )
    		{
    			cout << a[ i ] << "+" ;
    		}	
    		cout << a[ step - 1 ] << endl ;
    		return;
    	}
    	for ( int i = last ; i <= n ; i++)
    	{
    		a[ step ] = i ;
    		f ( n - i , i , step + 1 , k );
    	}
    }
    int main()
    {
    	cin >> n ;
    	f( n , 1 , 0 , n);
    	cout << "total=" << ans << endl ;
    	return 0;
    }
    
    
    

    信息

    ID
    1242
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    递交数
    353
    已通过
    158
    上传者