Ballot evaluation
Time Limit:1000MS Memory Limit:65536K
Total 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 |
//一看到此题就感觉map会比较简单,直接映射出值来。一遍就ac了。
//本题还要注意的一定是精度问题,由于double类型的精度3.2其实为3.19999999,这样的话会造成数据丢失
//处理办法为加上一个微小的增量,见代码。
#include
#include
int main()
{
int n,m,i,j,rateInt,k;
string name,s,str;
double rate;
map
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=0;i
cin>>name>>rate;
rateInt=(rate+0.0000001)*10;
data.insert(pair
}
k=0;
getline(cin,s);
for(j=0;j
k++;
getline(cin,s);
istringstream sin(s);
int sum=0,temp;
while(sin>>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
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==temp*10)
printf("Guess #%d was correct./n",k);
else
printf("Guess #%d was incorrect./n",k);
}
}
}
}