1 条题解

  • 0
    @ 2025-1-7 11:49:15

    C++ :

    #include <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;
    
    void init()
    {
    #ifndef ONLINE_JUDGE
    	freopen("lg.in", "r", stdin);
    	freopen("lg.out", "w", stdout);
    #endif
    }
    
    int a[10][10] =
    {
    	{1},
    	{1, 1},
    	{1, 2, 1},
    	{1, 3, 3, 1},
    	{1, 4, 6, 4, 1},
    	{1, 5, 10, 10, 5, 1},
    	{1, 6, 15, 20, 15, 6, 1},
    	{1, 7, 21, 35, 35, 21, 7, 1},
    	{1, 8, 28, 56, 70, 56, 28, 8, 1},
    	{1, 9, 36, 84, 126, 126, 84, 36, 9, 1}
    };
    
    int n, res;
    vector<int> vec;
    
    int main()
    {
    	init();
    	cin >> n >> res;
    	for (int i = 1; i <= n; i++)
    		vec.push_back(i);
    	do
    	{
    		int sum = 0;
    		for (int i = 0; i < n; i++)
    			sum += vec[i] * a[n - 1][i];
    		if (sum == res)
    		{
    			for (int i : vec)
    				cout << i << ' ';
    			return 0;
    		}
    	}
    	while (next_permutation(vec.begin(), vec.end()));
    	return 0;
    }
    
    • 1

    信息

    ID
    1087
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    (无)
    递交数
    1
    已通过
    0
    上传者