2 条题解

  • 0
    @ 2023-6-5 17:40:35
    #include <queue>
    #include <math.h>
    #include <stack>
    #include <vector>
    #include <stdio.h>
    #include <iostream>
    #include <vector>
    #include <iomanip>
    #include <string.h>
    #include<cstring>
    #include <algorithm>
    #define LL long long
    const int N = 1e2 + 10;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    int n , ans , a[N] ;
    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
    标签
    递交数
    304
    已通过
    137
    上传者