16
#include <iostream> #include <cmath> using namespace std; int N,M; //#balls, #draw int target; //目標值 int count=0; int power(int n,int m){ int result=1; for (int i=0;i<m;i++){result*=n;} return result; } int main () { cin >> N >> M; int size=power(N,M); int *A=new int[M]; int *B=new int[N]; //讀進N顆球的數字 for (int j=0;j<N;j++){ cin >> B[j]; } cin >> target; for (int i=0;i<size;i++){ int a=i; for (int j=0;j<M;j++){ A[j]= a%N ; a = a/N; } int amount=0; amount+=B[A[M-1]]; for (int j=1;j<M;j++){ amount+=B[A[M-j-1]]; } if (amount==target){ count++; } } cout << count; }
沒有留言:
張貼留言