Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- long permutations(long n, long k){
- long result = 1;
- for (int i = 0; i < k; ++i){
- result *= n-i;
- }
- return result;
- }
- int main(){
- int n, k, x;
- scanf("%d %d %d", &n, &k, &x);
- long result = 0;
- long value;
- if(x == 0){
- while(1 == scanf("%ld",&value));
- result = value;
- }else if (x == 1){
- if (k == 0){
- while(1 == scanf("%ld", &value)){
- result += value;
- }
- }else{
- int index = 0;
- while(1 == scanf("%ld",&value)){
- result += value*permutations(n-index,k);
- index++;
- }
- }
- }else if (x == -1){
- if(k == 0){
- short index = (n-k) % 2 ? -1 : 1;
- while(1 == scanf("%ld",&value)){
- result += index*value;
- index *= -1;
- }
- }else{
- short flag = (n-k) % 2 ? -1 : 1;
- int index = 0;
- while(1 == scanf("%ld",&value)){
- result += flag*value*permutations(n-index,k);
- flag *= -1;
- index++;
- }
- }
- }else{
- int index = 0;
- while(index <= (n-k) && 1 == scanf("%ld",&value)){
- result += value*permutations(n-index,k);
- if(index != (n-k)){
- result *= x;
- }
- index++;
- }
- }
- printf("%ld\n", result);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement