Ballot Evaluation

Ballot evaluation
Time Limit:1000MS  Memory Limit:65536KTotal Submit:26 Accepted:4
Description
Bruce Force has gone to Las Vegas, the El Dorado for gamblers. He is interested especially in one betting game, where a machine forms a sequence of n numbers by drawing random numbers. Each player should estimate beforehand, how many increasing subsequences of length k will exist in the sequence of numbers. A subsequence of a sequence a1, ..., an is defined as ai1, ..., ail, where 1 ≤ i1 < i2 < ... < il ≤ n. The subsequence is increasing, if aij-1 < aij for all 1 < j ≤ l. Bruce doesn't trust the Casino to count the number of increasing subsequences of length k correctly. He has asked you if you can solve this problem for him.
Input
The input contains several test cases. The first line of each test case contains two numbers n and k (1 ≤ k ≤ n ≤ 100), where n is the length of the sequence drawn by the machine, and k is the desired length of the increasing subsequences. The following line contains n pairwise distinct integers ai (-10000 ≤ ai ≤ 10000 ), where ai is the ith number in the sequence drawn by the machine. The last test case is followed by a line containing two zeros.
Output
For each test case, print one line with the number of increasing subsequences of length k that the input sequence contains. You may assume that the inputs are chosen in such a way that this number fits into a 64 bit signed integer (in C/C++, you may use the data type "long long", in Java the data type "long").
Sample Input
10 5
1 2 3 4 5 6 7 8 9 10
3 2
3 2 1
0 0

 
Sample Output
252
0

 
Source
2008/2009 University of Ulm Local Contest
 
chg
1261
Accepted
388K
734MS
G++
1.5K
2010-05-09 00:19:09
//이 문제를 보자마자 맵이 비교적 간단할 것 같아서 값을 직접 비추었다.한 번에 ac야.
//본고에서 주의해야 할 것은 반드시 정밀도 문제이다. 더블 유형의 정밀도 3.2는 사실 3.19999999이기 때문에 이렇게 하면 데이터 분실을 초래할 수 있다
//처리 방법은 미세한 증량을 더하기 위해 코드를 보십시오.
#include#include#includeusing namespace std;
int main(){ int n,m,i,j,rateInt,k; string name,s,str; double rate; map data; while(scanf("%d%d",&n,&m)!=EOF) {  for(i=0;i>name>>rate;   rateInt=(rate+0.0000001)*10;   data.insert(pair(name,rateInt));  }  k=0;  getline(cin,s);  for(j=0;j>str)   {    if(str=="+")     continue;    else if(str!="<"&&str!=">="&&str!="<="&&str!=">"&&str!="=")    {     temp=data[str];     sum+=temp;    }    else if(str=="<"||str==">="||str=="<="||str==">"||str=="=")     break;   }   sin>>temp;   if(str==">")   {    if(sum>temp*10)     printf("Guess #%d was correct./n",k);    else     printf("Guess #%d was incorrect./n",k);   }   else if(str==">=")   {    if(sum>=temp*10)     printf("Guess #%d was correct./n",k);    else     printf("Guess #%d was incorrect./n",k);   }   else if(str=="<")   {    if(sum

좋은 웹페이지 즐겨찾기