답안 #985119

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
985119 2024-05-17T10:50:08 Z ShauryaTheShep 순열 (APIO22_perm) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric> // Include this header for iota

using namespace std;

// Function to count the number of increasing subsequences
int countIncreasingSubsequences(const vector<int>& permutation) {
    int n = permutation.size();
    vector<int> dp(n, 1); // dp[i] will store the number of increasing subsequences ending at index i
    
    int totalCount = 0;
    
    // Calculate the number of increasing subsequences ending at each index
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < i; ++j) {
            if (permutation[j] < permutation[i]) {
                dp[i] += dp[j];
            }
        }
        totalCount += dp[i];
    }
    
    return totalCount;
}

// Function to construct a permutation with exactly k increasing subsequences
vector<int> construct_permutation(int64_t k) {
    int n = 2;
    vector<int> permutation;
    
    while (true) {
        permutation.resize(n);
        iota(permutation.begin(), permutation.end(), 1); // Create permutation starting from 1
        
        do {
            if (countIncreasingSubsequences(permutation) == k) {
                return permutation;
            }
        } while (next_permutation(permutation.begin(), permutation.end()));
        
        ++n;
    }
    
    return {}; // Should not reach here if k is within valid range
}

Compilation message

/usr/bin/ld: /tmp/ccBNOpOk.o: in function `main':
grader.cpp:(.text.startup+0x240): undefined reference to `construct_permutation(long long)'
collect2: error: ld returned 1 exit status