2014年5月12日 星期一

n顆不同的球,抽m次,每次都放回,列出所有可能(不介意是否由大而小的話

#include <iostream>
#include <cmath>
using namespace std;
int N,M; //#balls, #draw
int main () { 
 cin >> N >> M;
 int size=(int)pow((float)N,(float)M);
 for (int i=0;i<size;i++){
  int a=i;
  for (int j=0;j<M;j++){
   cout << a%N << ' ';
   a = a/N;
  }  
  cout << endl;
 }
}


3 2

0 0 
1 0 
2 0 
0 1 
1 1 
2 1 
0 2 
1 2 
2 2 

沒有留言:

張貼留言