标签:perm least 整数 graphic ios puts and mit tip
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10772 | Accepted: 6068 |
Description
3 1 2 4Behind FJ‘s back, the cows have started playing a more difficult game, in which they try to determine the starting sequence from only the final total and the number N. Unfortunately, the game is a bit above FJ‘s mental arithmetic capabilities.
4 3 6
7 9
16
Input
Output
Sample Input
4 16
Sample Output
3 1 2 4
Hint
#include<iostream> #include<string.h> #include<string> #include<algorithm> #include<queue> using namespace std; int a[15],b[15]; int n,cnt,ans,sum; int main() { while(cin>>n>>sum) { for(int i=0;i<n;i++) a[i]=i+1; do { for(int i=0;i<n;i++) b[i]=a[i]; for(int i=0;i<n-1;i++) { for(int j=0;j+1<n;j++) b[j]=b[j+1]+b[j]; } if(b[0]==sum) { for(int i=0;i<n;i++) { if(i==0) cout<<a[i]; else cout<<‘ ‘<<a[i]; } cout<<endl; break; } }while(next_permutation(a,a+n)); } }
标签:perm least 整数 graphic ios puts and mit tip
原文地址:https://www.cnblogs.com/-citywall123/p/11295143.html