通常,您可以将任意属性设置为自定义对象
----------
>>> a=A()
>>> a.foo=42
>>> a.__dict__
{'foo': 42}
>>>
----------
Run Code Online (Sandbox Code Playgroud)
另一方面,您不能对字符串对象进行相同的绑定:
----------
>>> a=str("bar")
>>> a.foo=42
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'foo'
>>> a.__dict__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute '__dict__'
>>>
----------
Run Code Online (Sandbox Code Playgroud)
为什么?
考虑以下与图论有关的问题:
设G是二分图.为了使问题更具体,假设G是两组的不相交联合,比如I和S.假设
所以,每个人都有一些技能,例如,
[在示例中,数据是随机给出的].
我们的目标是建立一个对团队组成最小的个体数我在这样每个在技能小号将在团队表示,这是每个技能小号的小号,存在具有技能一个团队的成员s.
这个问题有名字吗?是否知道解决它的有效算法?