当前位置:网站首页>码蹄集 万民堂大厨
码蹄集 万民堂大厨
2022-07-25 22:47:00 【Elvin域文】
运行时错误:
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
vector<vector<long long int>> res;
vector<long long int> arr2;
long long int target;
long long int start,last=0;
vector<long long int> temp;
long long int tim=0;
int OK(vector<long long int>a,long long int k,long long int i)//判断是否有重复元素
{
if(i>k)//保证数组存在的时候
for(int t=k;t<i;t++)//循环查找
{
if(a[t]==a[i])
return 0;
}
return 1;
}
void Perm(vector<long long int>a,long long int k,long long int m)//全排列的实现函数
{
if(k==m)//只剩下1个元素
{
tim++;//次数+1
// for(int i=0;i<=m;i++)
// {
// cout<<a[i];
// }
// cout<<"\n";
}
else //还有多个元素待排列
{
for(int i=k;i<=m;i++)//有几个元素就循环几次(因为以它打头,然后对后面的数进行全排列)
{
if(OK(a,k,i))//当不存在重复元素的时候,才进行全排列
{
swap(a[k],a[i]);//进行交换
Perm(a,k+1,m);
swap(a[k],a[i]);
}
}
}
}
int helper(vector<long long int> arr, long long int target, vector<long long int> arr2, long long int index){
if(target==0)
{
res.insert(res.end(),arr2);
}
for(int i=index; i<arr.size();i++){
if(arr[i] <= target){
arr2.insert(arr2.end(),arr[i]);
helper(arr, target-arr[i], arr2, i);
arr2.pop_back();
}
}
}
vector<vector<long long int>> combinationSum(vector<long long int> arr, long long int target){
helper(arr, target, arr2, 0);
return res;
}
int main()
{
vector<long long int> arr; //原始数组
long long int n,m,k,x;
cin >> x >> n >> m >> k;
target = x;
arr.insert(arr.end(),n);
arr.insert(arr.end(),m);
arr.insert(arr.end(),k);
combinationSum(arr,target);
for(int i=0;i<res.size();i++){
for(int j=0;j<res[i].size();j++){
start = 0;
temp.insert(temp.end(), res[i][j]);
}
last = res[i].size()-1;
Perm(temp, start, last);
temp.clear();
}
if(tim){
cout << tim%mod;
}
else{
cout << "impossible";
}
// cout << "组成的数量为:" << tim ;
return 0;
}边栏推荐
猜你喜欢

Anaconda~Upload did not complete.

Examples and points for attention about the use of getchar and scanf
![[training Day12] min ratio [DFS] [minimum spanning tree]](/img/f8/e37efd0d2aa0b3d79484b9ac42b7eb.png)
[training Day12] min ratio [DFS] [minimum spanning tree]

【集训DAY15】Boring【树形DP】

JVM内存区域

Hcie is finally in hand, and the road begins

Session and cookie, token and storage

JVM memory area

Simple setting of drop-down triangle
![[PMP learning notes] Chapter 1 Introduction to PMP System](/img/80/144124af40f0a015c4deafc3aa7432.png)
[PMP learning notes] Chapter 1 Introduction to PMP System
随机推荐
access-list vs ip access-list
Qtreewidget control of QT
面试题 17.11. 单词距离 ●●
Interview question 17.11. word distance ●●
【集训DAY13】Out race【数学】【动态规划】
Matrixcube unveils the complete distributed storage system matrixkv implemented in 102-300 lines
QVariant的使用
LabVIEW 开发 PCI-1680U双端口CAN卡
[training Day12] min ratio [DFS] [minimum spanning tree]
Two methods of printing strings in reverse order in C language
[training day13] travel [violence] [dynamic planning]
The third programming competition of Wuhan University of technology b- save the kingdom of DAG (topological properties deal with accessibility Statistics)
TFrecord写入与读取
[training day13] out race [mathematics] [dynamic planning]
Extended configuration of static routing in the second experiment
Data type conversion
新媒体运营策略(以小红书为例)帮助你快速掌握爆款创作方法
Floating effect and characteristics
JS makes elements get or lose focus
[training Day11] Calc [mathematics]