最近做的都是英文题,正好顺手测试一下各翻译网站的翻译能力。

原文

Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering problems, all the stalls in the new barn are different. For the first week, Farmer John randomly assigned cows to stalls, but it quickly became clear that any given cow was only willing to produce milk in certain stalls. For the last week, Farmer John has been collecting data on which cows are willing to produce milk in which stalls. A stall may be only assigned to one cow, and, of course, a cow may be only assigned to one stall.
Given the preferences of the cows, compute the maximum number of milk-producing assignments of cows to stalls that is possible.

The input includes several cases. For each case, the first line contains two integers, N (0 <= N <= 200) and M (0 <= M <= 200). N is the number of cows that Farmer John has and M is the number of stalls in the new barn. Each of the following N lines corresponds to a single cow. The first integer (Si) on the line is the number of stalls that the cow is willing to produce milk in (0 <= Si <= M). The subsequent Si integers on that line are the stalls in which that cow is willing to produce milk. The stall numbers will be integers in the range (1..M), and no stall will be listed twice for a given cow.

For each case, output a single line with a single integer, the maximum number of milk-producing stall assignments that can be made.


- 阅读剩余部分 -

2017-04-16更新:

void init_prime(int n) //欧拉素数筛法
{
    for(int i = 2; i <= n; i++)
    {
        if(!prime[i])
            prime[++prime[0]] = i;
        for(int j = 1; j <= prime[0] && prime[j] <= n / i; j++)
        {
            prime[prime[j] * i] = 1;
            if(i % prime[j] == 0)
                break;
        }
    }
}

以下是原文

- 阅读剩余部分 -

快速幂:a的b次方对n取余

int ksm(int a, int b, int n)
{
    a %= n;
    int ans = 1;
    while(b)
    {
        if(b%2 == 1)
            ans = ans*a%n;
        b /= 2;
        a = a*a%n;
    }
    return ans;
}

第一次碰到需要剪枝优化的题

题目描述

设有n件工作分配给n个人。为第i个人分配工作j所需的费用为ci 。试设计一个算法,计算最佳工作分配方案,为每一个人都分配1 件不同的工作,并使总费用达到最小。

输入

第一行一个正整数n(1<=n<=20),接下来的n 行,每行n 个数,表示工作费用 。

输出

输出有m行,每行输出最小总费用。

样例输入

5
50 43 1 58 60
87 22 5 62 71
62 98 97 27 38
56 57 96 73 71
92 36 43 27 95

样例输出

144

第一次提交代码:






- 阅读剩余部分 -

以前一直以为栈是个很复杂的东西,今天第一次用这个东西写题居然一次AC,欣喜之余发篇文纪念一下 #(滑稽)

- 阅读剩余部分 -