We use cookies to improve your experience, for authentication and to ensure that we show you advertising that is relevant to you. If you continue without changing your settings, we'll assume that you are happy to receive all cookies on Ideone website. However, if you wish, you can change cookie settings of your browser at any time.
Embed source code on your page
source code clone
download
copy to clipboard
report bug / make suggestion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <algorithm>
#include <vector>
int main( ) {
int n, r;
std:: cin >> n;
std:: cin >> r;
std:: vector < bool > v( n) ;
for ( int i = 0 ; i < n; ++ i) {
v[ i] = ( i >= ( n - r) ) ;
}
do {
for ( int i = 0 ; i < n; ++ i) {
if ( v[ i] ) {
std:: cout << ( i+ 1 ) << " " ;
}
}
std:: cout << "\n " ;
} while ( std:: next_permutation ( v.begin ( ) , v.end ( ) ) ) ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgoKaW50IG1haW4oKSB7CiAgICBpbnQgbiwgcjsKICAgIHN0ZDo6Y2luID4+IG47CiAgICBzdGQ6OmNpbiA+PiByOwoKICAgIHN0ZDo6dmVjdG9yPGJvb2w+IHYobik7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkgewogICAgICAgIHZbaV0gPSAoaSA+PSAobiAtIHIpKTsKICAgIH0KCiAgICBkbyB7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgICAgICAgICAgaWYgKHZbaV0pIHsKICAgICAgICAgICAgICAgIHN0ZDo6Y291dCA8PCAoaSsxKSA8PCAiICI7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgc3RkOjpjb3V0IDw8ICJcbiI7CiAgICB9IHdoaWxlIChzdGQ6Om5leHRfcGVybXV0YXRpb24odi5iZWdpbigpLCB2LmVuZCgpKSk7Cn0K
clone
download
copy to clipboard
input / output show all
hide all
upload with new input
result:
Success
time: 0s
memory: 2988 kB
returned value: 0
output:
4 5
3 5
3 4
2 5
2 4
2 3
1 5
1 4
1 3
1 2
result:
Success
time: 0.02s
memory: 2860 kB
returned value: 0
output:
4 5 6
3 5 6
3 4 6
3 4 5
2 5 6
2 4 6
2 4 5
2 3 6
2 3 5
2 3 4
1 5 6
1 4 6
1 4 5
1 3 6
1 3 5
1 3 4
1 2 6
1 2 5
1 2 4
1 2 3
result:
Success
time: 0.01s
memory: 2816 kB
returned value: 0
output:
7 8
6 8
6 7
5 8
5 7
5 6
4 8
4 7
4 6
4 5
3 8
3 7
3 6
3 5
3 4
2 8
2 7
2 6
2 5
2 4
2 3
1 8
1 7
1 6
1 5
1 4
1 3
1 2
result:
Success
time: 0.01s
memory: 2860 kB
returned value: 0
output:
3 4 5
2 4 5
2 3 5
2 3 4
1 4 5
1 3 5
1 3 4
1 2 5
1 2 4
1 2 3
author's note
show 3 element combinations of {1, 2, 3, 4, 5}
Choose your language:
Help us translate Ideone - click here