2013
11-09

# Moving Computer

Assurance Company of Moving (ACM) is a company of moving things for people. Recently, some schools want to move their computers to another place. So they ask ACM to help them. One school reserves K trucks for moving, and it has N computers to move. In order not to waste the trucks, the school ask ACM to use all the trucks. That is to say, there must be some computers in each truck, and there are no empty trucks. ACM wants to know how many partition shemes exists with moving N computers by K trucks, the ACM ask you to compute the number of different shemes with given N and K.

You needn’t care with the order. For example N=7,K=3, the the following 3 partition instances are regarded as the same one and should be counted as one sheme.

1 1 5

1 5 1

5 1 1

Each truck can carry 200 computers at most.

Each line of the input contains two postisive integer N (1<=N<=200) and K(1<=K<=N).Input is terminated by a line with N=K=0.

For each line, output the number of different partition sheme . The result may be larger than 2^32, so you should care with the precision.

1 1
7 3
0 0


1
4

The four partition shemes of the second sample are:

1 1 5

1 2 4

1 3 3

2 2 3

//* @author:

/*
题意：给定N台电脑和K辆卡车，要求每辆卡车至少放一台电脑。问共有多少种放法？

import java.util.*;
public class Main{

private long dp[][]=new long[201][201];

public Main(){
init();
}
private  void init(){
for(int i=1;i< 201;i++)
{
dp[i][i]=dp[1][i]=dp[i][0]=dp[0][i]=1;
}
for(int i=2;i< 201;i++)
{
for(int j=i+1;j< 201;j++)
{

dp[i][j]=dp[i-1][j-1]+dp[i][j-i];
}
}
}

public long dp(int k,int n){
return dp[k][n];
}

public static void main(String args[]){
Scanner in=new Scanner(System.in);
Main m=new Main();
while(true){
int n=in.nextInt();
int k=in.nextInt();
if(n==0 && k==0) break;
System.out.println(m.dp(k,n));
}
}
}

1. 其实国内大部分公司对算法都不够重视。特别是中小型公司老板根本都不懂技术，也不懂什么是算法，从而也不要求程序员懂什么算法，做程序从来不考虑性能问题，只要页面能显示出来就是好程序，这是国内的现状，很无奈。

2. #!/usr/bin/env python
def cou(n):
arr =
i = 1
while(i<n):
arr.append(arr[i-1]+selfcount(i))
i+=1
return arr[n-1]

def selfcount(n):
count = 0
while(n):
if n%10 == 1:
count += 1
n /= 10
return count

3. 这道题目虽然简单，但是小编做的很到位，应该会给很多人启发吧！对于面试当中不给开辟额外空间的问题不是绝对的，实际上至少是允许少数变量存在的。之前遇到相似的问题也是恍然大悟，今天看到小编这篇文章相见恨晚。

4. Gucci New Fall Arrivals

This is really nice to know. I hope it will be successful in the future. Good job on this and keep up the good work.

5. int half(int *array,int len,int key)
{
int l=0,r=len;
while(l<r)
{
int m=(l+r)>>1;
if(key>array )l=m+1;
else if(key<array )r=m;
else return m;
}
return -1;
}
这种就能避免一些Bug
l,m,r
左边是l,m;右边就是m+1,r;